#region SetDropDownByValue
public void SetDropDownByValue(System.Web.UI.WebControls.DropDownList dbo,
string Value)
{
for (int x = 0; x < dbo.Items.Count; x++) {
if (dbo.Items[x].Value.Equals(Value)) { dbo.SelectedIndex = x; break; }
}
}
#endregion
#region SetDropDownByText
public void SetDropDownByText(System.Web.UI.WebControls.DropDownList dbo,
string Text)
{
for (int x = 0; x < dbo.Items.Count; x++) {
if (dbo.Items[x].Text.Equals(Text)) { dbo.SelectedIndex = x; break; }
}
}
#endregion
Using these functions saves me a number of lines of code and allows me to set dropdownlists by text or value depending on what data we have.
Enjoy!
No comments:
Post a Comment