本文介绍了如何绑定CalendarExtender日期更改下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个CalendarExtender连接到文本框.我需要在服务器端捕获DateChange事件,以便可以根据选定的日期用数据库中的项目填充DropDownList.
Hello ,
I have a CalendarExtender connected to a textbox. i need to catch the DateChange event in the server side so i can populate a DropDownList with items from my DB according to the selected date.
推荐答案
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=IT-DEV2\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
string statment = string.Format("select item_code, Item_name, brand, size, section, price, Material, Qty, tax,tDate from Items where tDate ='{0}'", TextBox2.Text);
SqlDataAdapter da = new SqlDataAdapter(statment, con);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataTextField = "Item_name";
DropDownList1.DataValueField = "item_code";
DropDownList1.DataBind();
}
<div>
<asp:TextBox ID="TextBox2" runat="server" ontextchanged="TextBox2_TextChanged"></asp:TextBox>
<asp:CalendarExtender ID="TextBox2_CalendarExtender" runat="server"
Enabled="True" TargetControlID="TextBox2">
</asp:CalendarExtender>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</div>
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于如何绑定CalendarExtender日期更改下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!