In
this article I am going to explain how to set selected value in dropdownlist on
page load from code behind in asp.net using C# and vb.net
Implementation:
HML Markup:
<asp:DropDownList ID="ddlItems" runat="server" CssClass="dropdownlist">
<asp:ListItem Value="-1">--Select Item--</asp:ListItem>
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
</asp:DropDownList>
Set selected
value on page load
C# Code:
protected void Page_Load(object
sender, EventArgs e)
{
if
(!IsPostBack)
{
ddlItems.Items.FindByText("Item 3").Selected = true;
}
}
VB.net Code:
Protected Sub Page_Load(sender As
Object, e As
System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ddlItems.Items.FindByText("Item 3").Selected = True
End If
End Sub
0 Comments