如何在文本框选择索引更改时绑定下拉列表? [英] How to bind dropdownlist when textbox selected index changed?

查看:64
本文介绍了如何在文本框选择索引更改时绑定下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一个下拉列表的textbow,如下所示,

I have one textbow with one dropdownlist as shown below,

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<table>
<tr>
<td>
<asp:TextBox ID="fromTxt" runat="server" AutoPostBack="true" 

        ontextchanged="fromTxt_TextChanged"></asp:TextBox>
        <asp:CalendarExtender ID="calExt1" runat="server" Format="dd/MM/yyyy" TargetControlID="fromTxt" PopupButtonID="fromTxt"></asp:CalendarExtender>
</td>
<td>
<asp:DropDownList ID="ddTodate" runat="server"></asp:DropDownList>
</td>
</tr>
</table>



我想在textbox(fromtxt)textchanged事件中的下拉列表(ddTodate)中绑定接下来30天的日期。 />


I want to bind next 30 days date in dropdownlist(ddTodate) from textbox(fromtxt) textchanged event.

protected void fromTxt_TextChanged(object sender, EventArgs e)
{
//I have to bind Dropdownlist with next 30 days date from the date selected in textbox.
}



例如,如果我在textbow(fromtxt)中选择日期(15/11/2014),则下拉列表应该像这样绑定,

16/11/2014

17/11/2014

18/11/2014

....

....

....

....

....

....

....

15/12/2014





先谢谢,

R @ JE $#


for example,if i select date like (15/11/2014) in textbow(fromtxt) then the dropdownlist should bind like this,
16/11/2014
17/11/2014
18/11/2014
....
....
....
....
....
....
....
15/12/2014


Thanks in Advance,
R@JE$#

推荐答案


嗨R @ jes#,

最好你可以在Sql中使用CTE

这是查询和修改它,







Hi R@jes#,
Better you can use CTE in Sql
Here is the Query and Modify it ,



DECLARE @Date Datetime = getdate()
Declare @endDate Datetime=Dateadd(month,1,@date);
;WITH CTE AS
(
    SELECT @Date as dates UNION ALL
    SELECT DATEADD(day,1,dates) FROM CTE where dates<@endDate
)
SELECT dates AS Date FROM CTE







编辑:






Edited:

DECLARE @Date Datetime = getdate()
Declare @endDate Datetime=Dateadd(month,1,@date);
;WITH CTE AS
(
    SELECT @Date as dates,1 as no UNION ALL
    SELECT DATEADD(day,1,dates),no+1 FROM CTE where dates<@endDate
)
SELECT dates AS Date ,no FROM CTE





您可以将查询结果绑定到下拉列表



You can Bind The Query Result to your Dropdown List


试试这个...你会得到你的解决方案..



Try This ... You Will Get Your Solution..

DateTime fromDate = [Your calender Date (TextBox date)];

   for(int i=0; i< 30;i++)
   {
       fromDate = fromDate.AddDays(1);
           ddTodate.Items.Insert(i,fromDate.ToString("dd/MM/yyyy"));

   }







谢谢

AARIF SHAIKH




Thanks
AARIF SHAIKH


这篇关于如何在文本框选择索引更改时绑定下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆