Select Item in List Control

Rajni.Shekhar
Posted by Rajni.Shekhar under ASP.NET category on | Points: 40 | Views : 1131
Page.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<p>
&nbsp;</p>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Value="1">Text1</asp:ListItem>
<asp:ListItem Value="2">Text2</asp:ListItem>
<asp:ListItem Value="3">Text3</asp:ListItem>
</asp:ListBox>
</form>
</body>
</html>


Page.aspx.cs

ListBox1.SelectedIndex = ListBox1.Items.IndexOf(ListBox1.Items.FindByText("Text1"));

Comments or Responses

Login to post response