Updated on Kisan Patel
This post will show you how to write “Please select …” as the first item in the DropDownList
control while populating them from the server side in ASP.NET.
Default.aspx
<asp:DropDownList ID="dropDownList1" runat="server"> </asp:DropDownList>
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDataNow(); } } private void PopulateDataNow() { // populate the data into the DropDownList dropDownList1.DataSource = GetData(); //Your Data Source dropDownList1.DataBind(); dropDownList1.Items.Insert(0, new ListItem("Please Select ...", "0")); }
In above code, the DropDownList is populated from the code behind needs to write “Please select …” using the dropDownList1.Items.Insert(0, new ListItem("Please Select ...", "0"));
method by specifying the index as 0 so that it appears as the first item.