asp.net(C#)的DropDownList控件怎么数据绑定 30
求解这段代码的意思,在线等stringff="SELECTid=SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+...
求解这段代码的意思,在线等
string ff = "SELECT id=SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+',',number)-number) FROM tb_Teacher a,master..spt_values WHERE number<=LEN(a.teaclass) AND SUBSTRING(','+a.teaclass,number,1)=',' and a.id='" + zid + "' GROUP BY SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+',',number)-number) ";
DataTable df = DBUtility.DbHelperSQL.Query(ff).Tables[0];
DataTable dt1 = new DataTable();
dt1.Columns.Add("id");
dt1.Columns.Add("name");
for (int i = 0; i < df.Rows.Count; i++)
{
string sa2 = "select * from tb_Classag where id=" + Convert.ToInt32(df.Rows[i]["id"]);
DataTable ds = DBUtility.DbHelperSQL.Query(sa2).Tables[0];
if (ds.Rows.Count > 0)
{
dt1.Rows.Add(Int32.Parse(ds.Rows[0]["id"].ToString()), ds.Rows[0]["name"]);
}
}
DropDownList3.DataSource = dt1;
DropDownList3.DataTextField = "name"; //文本内容字段
DropDownList3.DataValueField = "id"; //值字段
DropDownList3.DataBind();
string ff = "SELECT
id=SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+',',number)-number)
FROM tb_Teacher a,master..spt_values WHERE number<=LEN(a.teaclass)
AND SUBSTRING(','+a.teaclass,number,1)=',' and a.id='" + zid + "' GROUP
BY
SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+',',number)-number)
";
我自己想做的东西是绑定通过personal_customer表里的endcationid字段查找出education表的学历字段,然后显示在DropDownList
控件上,还可以把用户选择的下拉选项内容改变personal_customer表里的endcationid字段值同时改变education表的学历字段值 展开
string ff = "SELECT id=SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+',',number)-number) FROM tb_Teacher a,master..spt_values WHERE number<=LEN(a.teaclass) AND SUBSTRING(','+a.teaclass,number,1)=',' and a.id='" + zid + "' GROUP BY SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+',',number)-number) ";
DataTable df = DBUtility.DbHelperSQL.Query(ff).Tables[0];
DataTable dt1 = new DataTable();
dt1.Columns.Add("id");
dt1.Columns.Add("name");
for (int i = 0; i < df.Rows.Count; i++)
{
string sa2 = "select * from tb_Classag where id=" + Convert.ToInt32(df.Rows[i]["id"]);
DataTable ds = DBUtility.DbHelperSQL.Query(sa2).Tables[0];
if (ds.Rows.Count > 0)
{
dt1.Rows.Add(Int32.Parse(ds.Rows[0]["id"].ToString()), ds.Rows[0]["name"]);
}
}
DropDownList3.DataSource = dt1;
DropDownList3.DataTextField = "name"; //文本内容字段
DropDownList3.DataValueField = "id"; //值字段
DropDownList3.DataBind();
string ff = "SELECT
id=SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+',',number)-number)
FROM tb_Teacher a,master..spt_values WHERE number<=LEN(a.teaclass)
AND SUBSTRING(','+a.teaclass,number,1)=',' and a.id='" + zid + "' GROUP
BY
SUBSTRING(a.teaclass,number,CHARINDEX(',',a.teaclass+',',number)-number)
";
我自己想做的东西是绑定通过personal_customer表里的endcationid字段查找出education表的学历字段,然后显示在DropDownList
控件上,还可以把用户选择的下拉选项内容改变personal_customer表里的endcationid字段值同时改变education表的学历字段值 展开
展开全部
DataTable df = DBUtility.DbHelperSQL.Query(ff).Tables[0]; //查表tb_Teacher
DataTable dt1 = new DataTable();
dt1.Columns.Add("id");
dt1.Columns.Add("name");
for (int i = 0; i < df.Rows.Count; i++)//遍历所有行,查tb_Classag表中 id=id
{
string sa2 = "select * from tb_Classag where id=" + Convert.ToInt32(df.Rows[i]["id"]);
DataTable ds = DBUtility.DbHelperSQL.Query(sa2).Tables[0];
if (ds.Rows.Count > 0)//如果查到,添加到dt1
{
dt1.Rows.Add(Int32.Parse(ds.Rows[0]["id"].ToString()), ds.Rows[0]["name"]);
}
}
DropDownList3.DataSource = dt1; //DropDownList3 绑带数据,显示 DropDownList3.DataTextField = "name"; //文本内容字段
DropDownList3.DataValueField = "id"; //值字段
DropDownList3.DataBind();
DataTable dt1 = new DataTable();
dt1.Columns.Add("id");
dt1.Columns.Add("name");
for (int i = 0; i < df.Rows.Count; i++)//遍历所有行,查tb_Classag表中 id=id
{
string sa2 = "select * from tb_Classag where id=" + Convert.ToInt32(df.Rows[i]["id"]);
DataTable ds = DBUtility.DbHelperSQL.Query(sa2).Tables[0];
if (ds.Rows.Count > 0)//如果查到,添加到dt1
{
dt1.Rows.Add(Int32.Parse(ds.Rows[0]["id"].ToString()), ds.Rows[0]["name"]);
}
}
DropDownList3.DataSource = dt1; //DropDownList3 绑带数据,显示 DropDownList3.DataTextField = "name"; //文本内容字段
DropDownList3.DataValueField = "id"; //值字段
DropDownList3.DataBind();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询