asp.net(C#)的DropDownList控件怎么数据绑定
我自己想做的东西是绑定通过personal_customer表里的endcationid字段查找出education表的学历字段,然后显示在DropDownList控件上...
我自己想做的东西是绑定通过personal_customer表里的endcationid字段查找出education表的学历字段,然后显示在DropDownList
控件上,还可以把用户选择的下拉选项内容改变personal_customer表里的endcationid字段值同时改变education表的学历字段值
前台:
<asp:DropDownList ID="DropDownList1" runat="server"
DataTextField="education" DataValueField="id"></asp:DropDownList>
.cs文件代码:
if (!IsPostBack)
{
if (Request.QueryString["upId"] == null)
{
string sql = " select * from education ";
DataTable dt = Maticsoft.DBUtility.DbHelperSQL.Query(sql).Tables[0];
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
return;
}
else
{
BindModel();
}
private void BindModel()
{
int id = int.Parse(Request.QueryString["upId"]);
string sql = "select a.*,b.id as eid,b.education from personal_customer a,education b where a.id = '" + id + "'";
DataTable dt = Maticsoft.DBUtility.DbHelperSQL.Query(sql).Tables[0];
name.Text = dt.Rows[0]["name"].ToString();
tel.Text = dt.Rows[0]["tel"].ToString();
sex.Text = dt.Rows[0]["sex"].ToString();
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
}
谢谢,在线等 展开
控件上,还可以把用户选择的下拉选项内容改变personal_customer表里的endcationid字段值同时改变education表的学历字段值
前台:
<asp:DropDownList ID="DropDownList1" runat="server"
DataTextField="education" DataValueField="id"></asp:DropDownList>
.cs文件代码:
if (!IsPostBack)
{
if (Request.QueryString["upId"] == null)
{
string sql = " select * from education ";
DataTable dt = Maticsoft.DBUtility.DbHelperSQL.Query(sql).Tables[0];
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
return;
}
else
{
BindModel();
}
private void BindModel()
{
int id = int.Parse(Request.QueryString["upId"]);
string sql = "select a.*,b.id as eid,b.education from personal_customer a,education b where a.id = '" + id + "'";
DataTable dt = Maticsoft.DBUtility.DbHelperSQL.Query(sql).Tables[0];
name.Text = dt.Rows[0]["name"].ToString();
tel.Text = dt.Rows[0]["tel"].ToString();
sex.Text = dt.Rows[0]["sex"].ToString();
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
}
谢谢,在线等 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询