2

I have an aspx page with some inputs. In one hand, i have the following two inputs to capture the range of dates:

<asp:TextBox ID="bDate" runat="server" TextMode="Date"></asp:TextBox>
<asp:TextBox ID="eDate" runat="server" TextMode="Date"></asp:TextBox>

and, at the bottom of the page, I have a dropdown that should be filled with a query like

select xxx from table where beginDate >= bDate and endDate <= eDate

The goal is to have this dropdown correctly populated with no need to click on any button.

PS: I have all the code on page load and the query correctly running (only select) so I should only want to know the knowledge to get this done.

palaѕн
  • 72,112
  • 17
  • 116
  • 136

2 Answers2

0

You can use OnTextChanged="DateTextChanged_OnTextChanged" on one (or both) of your textbox if both have value.

<asp:TextBox ID="bDate" runat="server" TextMode="Date" OnTextChanged="DateTextChanged_OnTextChanged" AutoPostBack="true"/>
<asp:TextBox ID="eDate" runat="server" TextMode="Date" OnTextChanged="DateTextChanged_OnTextChanged" AutoPostBack="true"/>

Then validate they have value in your code behind if they do call the business logic to get information to bind to your dropdown list.

protected void DateTextChanged_OnTextChanged(object sender, EventArgs e)
{
    // do validation run query     
}

NOTE: This with post back will reload the screen so your probably want to use an update panel or something similar.

hope that helps

Oliver Cooke
  • 1,059
  • 1
  • 8
  • 22
0

If you have a DropDownList called ddlSubject, you must do:

var query = select xxx from table where beginDate >= bDate and endDate <= eDate

ddlSubject.DataSource = query ;
ddlSubject.DataTextField = "SubjectNamne";
ddlSubject.DataValueField = "SubjectID";
ddlSubject.DataBind();

And be careful if is or isn't a PostBack process: What is a postback?

Because this can clean completely your DropDownList.

Stephan
  • 100
  • 5