关于三级联动数据绑定有关问题,小弟我用后台绑定数据,感觉不太协调,能不能优化一下
关于三级联动数据绑定问题,我用后台绑定数据,感觉不太协调,能不能优化一下?
后台数据绑定
前台代码
------解决方案--------------------
Refer here:
http://www.cnblogs.com/insus/archive/2011/07/04/2097059.html
http://www.cnblogs.com/insus/archive/2012/10/16/2725307.html
http://www.cnblogs.com/insus/p/3414480.html
http://www.cnblogs.com/insus/p/3426563.html
后台数据绑定
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
string id = TextBox1.Text;
SqlParameter[] val = new SqlParameter[] {
new SqlParameter("@id",id)
};
string sql = "select color from ruku where id=@id";
DataTable dt = DAL.DBHelper.GetDataSet(sql,val);
//DataTable dt1 = new DataTable();
//dt1.Columns.Add("col", typeof(System.String));
List<string> list = new List<string>();
foreach (DataRow r in dt.Rows)
{
string vale = r["color"].ToString();
if (!list.Contains(vale))
{
list.Add(vale);
}
}
DropDownList1.DataSource = list;
DropDownList1.DataBind();
}
前台代码
<div>
编号:<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
颜色:<asp:DropDownList ID="DropDownList1" Width="100px" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="查 询" Width="94px" OnClientClick="return fun()"
OnClick="Button1_Click" />
</div>
------解决方案--------------------
Refer here:
http://www.cnblogs.com/insus/archive/2011/07/04/2097059.html
http://www.cnblogs.com/insus/archive/2012/10/16/2725307.html
http://www.cnblogs.com/insus/p/3414480.html
http://www.cnblogs.com/insus/p/3426563.html