select item in dropdownlist & display in datalist
-
Hi there...im writing a program where basically a user should select his/her name from a dropdownlist and then all details pertaining to that particular user are displayed in the datalist. At the moment the datalist is displays records for all users. How do i bind the records in the datalist to the selected item in the dropdownlist? Any help much appreciated - Thanks :) Chrissy Callen
-
Hi there...im writing a program where basically a user should select his/her name from a dropdownlist and then all details pertaining to that particular user are displayed in the datalist. At the moment the datalist is displays records for all users. How do i bind the records in the datalist to the selected item in the dropdownlist? Any help much appreciated - Thanks :) Chrissy Callen
Hi there. You could create an event handler for the
OnSelectedIndexChanged
that re-binds the grid using theSelectedValue
of the dropdownlist. Also - make sure the dropdownlist has itsAutoPostBack
property set to true. Something like this maybe:<asp:DropDownList id="myDD" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="myDD_SelectedIndexChanged">
... items ...
</asp:DropDownList><asp:DataGrid id="myGrid" runat="server">
... stuff ...
</asp:DataGrid><script runat="server">
private void myDD_SelectedValueChanged(object sender,
EventArgs e)
{
// get the drop down selected value
string sValue = myDD.SelectedValue;// now re-execute whatever code was // binding the grid, applying sValue // as criteria BindMyGrid(sValue);
}
private BindMyGrid(string sValue)
{
// if the passed in value is null, bind all data
if (sValue == null)
// ... bind all data
else
// ... only bind the one record based on sValue
}</script>