This is an example of what you could have on an ASPX page:
<asp:DropDownList ID="ddlDb" runat="server">This is an example of how to set the selected item:
<asp:ListItem Value="all" Selected="True">All</asp:ListItem>
<asp:ListItem Value="opt1">Option One</asp:ListItem>
<asp:ListItem Value="opt2">Option Two</asp:ListItem>
</asp:DropDownList>
ListItem li = ddlDb.Items.FindByValue("opt1");Another method is below, but it will throw System.ArgumentOutOfRangeException if the value is not found:
if (li != null) ddlDb.SelectedIndex = ddlDb.Items.IndexOf(li);
ddlDb.SelectedValue = "opt1";
2 comments:
AOA,
hi m saif ur rehman, working as systems analyst, i was tired and at the same time i was facing a problem, for the dropdown selected value and ur sugession help me to remove this bug from the applicaitons, thanks
Saifi
Pakistan
if(drpdownlistName.Items.FindByValue(
"78") != null)
{
// Note: The above condition works for both the values
// 1) NULL 2) and even if the value is not found in the dropdownlist
}
Post a Comment