posted 1/5/2009 by Vijendra Shakya
We can insert the ListItem in Dropdownlist at any postion there is two ways to insert the listItem in the Dropdownlist.Always remember Add and Insert is different Insert takes 2 parameter and Add takes only one Parameter.syntax:
drpUserName.Items.Insert(0, new ListItem("Please Select User Name", "0")); drpUserName.Items.Add(new ListItem("Please Select User Name", "0"));
This will insert a ListItem to index 0,with "Please Select User Name" Text and 0 value and Add on the last index with "Please Select User Name" and 0 values.
We also Insert ListItem in Dropdownlist in the following ways.
<asp:DropDownList ID="drpUserName" AppendDataBoundItems="true" runat="server"> <asp:ListItem Text="Please Select UserName" Value="0" /> </asp:DropDownList>
<asp:DropDownList ID="drpUserName" AppendDataBoundItems="true" runat="server">
<asp:ListItem Text="Please Select UserName" Value="0" />
</asp:DropDownList>
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18