Here is how one should bind the drop-downlist...and why is it good?
Because, in most cases we are executing some logic like loading another drop-down list on change of selected index of the first one.
Make functions to bind respective drop-down lists. And call them when needed to re-bind.
Page_Load
{
BindFirstDropDown();
FirstDropDown.Items.Insert(0,new ListItem("Select", "0"));
if(SecondDropDown.Items.Count == 0)
SecondDropDown.Items.Add(new ListItem("Select", "0"));
}
FirstDropDown_IndexChanged(...)
{
BindSecondDropDown();
SecondDropDown.Items.Insert(0,new ListItem("Select", "0"));
}
void BindFirstDropDown()
{
...
}
void BindSecondDropDown()
{
...
}
Tuesday, July 3, 2007
Good practice about DropDownList Databinding
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment