C# 正在从会话加载Drop DownList并将其保存到DB
C# 正在从会话加载Drop DownList并将其保存到DB,c#,asp.net,session,C#,Asp.net,Session,我想知道如何从网格加载会话数据,并将其传递到下拉列表的下一页,然后将其保存在DB中。 例如:我的网格数据在第1页名称、地址、国家 protected void PassData(object sender, EventArgs e) { GridViewRow gr = ((sender as LinkButton).NamingContainer as GridViewRow); Session["Name"] = gr.Cells[3].Text.T
我想知道如何从网格加载会话数据,并将其传递到下拉列表的下一页,然后将其保存在DB中。
例如:我的网格数据在第1页名称、地址、国家
protected void PassData(object sender, EventArgs e)
{
GridViewRow gr = ((sender as LinkButton).NamingContainer as GridViewRow);
Session["Name"] = gr.Cells[3].Text.Trim();
Session["Address"] = gr.Cells[4].Text.Trim();
Session["Country"] = gr.Cells[5].Text.Trim();
}
我正要在第2页的国家/地区下拉列表中加载国家/地区值。我的下拉列表中有预加载的国家/地区列表,我必须加载会话[“国家/地区]中的国家/地区值。
例如:
所以我使用了代码..
ddlCountry.SelectedItem.Text = Session["Country"].ToString();
在我的页面中加载国家/地区列表
private void BindCountry()
{
DataTable dt = new DataTable();
dt = objUser.SelAllCountry();
objCommon.BindDropDown(ddlCountry, "CountryID", "CountryName", dt);
ddlCountry.SelectedValue = "1";
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCountry();
//BindState(1);
}
}
ddlCountry.SelectedItem.Text=其中存在我的会话值,但
无法将其存储在我的数据库中
我无法保存新值,它始终保留默认值1 USA页面加载
private void BindCountry()
{
DataTable dt = new DataTable();
dt = objUser.SelAllCountry();
objCommon.BindDropDown(ddlCountry, "CountryID", "CountryName", dt);
ddlCountry.SelectedValue = "1";
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCountry();
//BindState(1);
}
}
谁能帮我解决这个问题。。
提前感谢。您正在选择函数中的第一个值BindCountry()。请避免选择该值
private void BindCountry()
{
DataTable dt = new DataTable();
dt = objUser.SelAllCountry();
objCommon.BindDropDown(ddlCountry, "CountryID", "CountryName", dt);
}
避免使用此行..
ddlCountry.SelectedValue=“1”代码>我认为问题在于您正在页面加载()中的绑定下拉列表中,请尝试将绑定代码放入!IsPostback
条件块
编辑
尝试使用以下语法设置所选索引
ddlCountry.SelectedIndex = ddlCountry.Items.IndexOf(ddlCountry.Items.FindByText(Session["Country"].ToString()));
应将上面的内容替换为下面的内容
ddlCountry.SelectedItem.Text = Session["Country"].ToString();
显示您的页面加载()事件代码实际上我正在使用它!isPostBack是否绑定页面加载中的下拉列表?请发布页面加载事件?请在会话中传递国家/地区的id并使用ddlCountry。Selectedvalue=session[“id”]。tostring();执行此行后-ddlCountry.SelectedItem.Text=Session[“Country”].ToString()-您的下拉列表是否选择了特定国家?我的下拉列表将值设置为澳大利亚,但无法保存。。如果我保存,它将保存第一个值。