Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:DropDownList ID="ddlroomtype" runat="server">
<asp:ListItem Value="0" Selected="True">Please Select</asp:ListItem>
</asp:DropDownList>



i used above coding to show "please select" option in dropdownlist

in page load event

i have used c# coding to fetch data from database and bind to dropdownlist.after page get load unable to see "please select" option in dropdownlist., it have only binded values from database..
Posted

try this :

private void FillDropDownList()
    {
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("Select field  FROM tablename",con object);
        myda.Fill(ds);
        drop1.DataSource = ds;
        drop1.DataValueField = "field";
        drop1.DataBind();
        drop1.Items.Insert(0, new ListItem("--Please Select", "0"));
    }


and on Page Load

C#
if(!ispostback)
{
  FillDropDownList();
}



Thanks.....
 
Share this answer
 
v2
Comments
AshishChaudha 23-Oct-12 2:42am    
Good one
[no name] 23-Oct-12 2:42am    
thanks Ashish Bhai
Write the following code after binding the dropdownlist.

C#
ddlroomtype.Items.Insert(0, new ListItem("Please Select"));



Thanks
 
Share this answer
 
v3
Easy workaround. In your query, do a UNION with a "--please select---' clause.

For e.g.

C#
select id, name from mytable
UNION
select 0, '--please select---'
 
Share this answer
 
Comments
fjdiewornncalwe 23-Oct-12 14:22pm    
+5. Done this many times.
Abhinav S 24-Oct-12 13:00pm    
Thank you.
XML
<asp:DropDownList ID="DropDownList1" runat="server">
    <asp:ListItem>--Select This---</asp:ListItem>
</asp:DropDownList>



use the same as a list item and bind other value on the top of that.

Thanks,
Ambesha
 
Share this answer
 
Add this
DropDownList1.Items.Add("--please select--")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900