Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 04, 2008 04:39 AM by engineerachu
Member
19 Points
98 Posts
Nov 04, 2008 03:18 AM|LINK
I have been binding data from database to DropDownList , but i want to display "Please select one..." before database data in DropDownList one time when the page displayed, how can i do that?
Thanks,
Participant
978 Points
186 Posts
Nov 04, 2008 03:43 AM|LINK
Hi,
Add the ListItem to dropdown like this, before binding...
<asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Text="Please Select One..."></asp:ListItem> </asp:DropDownList>
and set the AppendDataBoundItems property of DropDownList to true .
59 Points
140 Posts
Nov 04, 2008 03:49 AM|LINK
Here's how you can insert the "Please select one..." as the initial item of your dropdownlist:
ListItem item = new ListItem();
item.Text = "Please select one...";
item.Value = string.Empty; //or whatever value you want to assign to it
item.Selected = true;
drpdownlist.Items.Insert(0, item); //this will insert the item at the top of you list
Let me know if it works.
All-Star
32487 Points
6742 Posts
Nov 04, 2008 03:54 AM|LINK
After binding data from database to Dropdonwlist
set AppendDataboundItems=True
dropdonwlist1.items.insert(0,new listitem("--Select--"))
Contributor
3077 Points
850 Posts
Nov 04, 2008 04:39 AM|LINK
Hope this is what you asked:
In Page_Load if(!Page.IsPostBack) { ddlSort.Items.Insert(0, new ListItem("-- Please select One --", "0")); }
minhpg
Member
19 Points
98 Posts
How to add "Please select one..." to DropDownList control when it is binding with database?
Nov 04, 2008 03:18 AM|LINK
I have been binding data from database to DropDownList , but i want to display "Please select one..." before database data in DropDownList one time when the page displayed, how can i do that?
Thanks,
kashmirindot...
Participant
978 Points
186 Posts
Re: How to add "Please select one..." to DropDownList control when it is binding with database?
Nov 04, 2008 03:43 AM|LINK
Hi,
Add the ListItem to dropdown like this, before binding...
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="Please Select One..."></asp:ListItem>
</asp:DropDownList>
and set the AppendDataBoundItems property of DropDownList to true .
Tahir.
gulrnpink
Member
59 Points
140 Posts
Re: How to add "Please select one..." to DropDownList control when it is binding with database?
Nov 04, 2008 03:49 AM|LINK
Here's how you can insert the "Please select one..." as the initial item of your dropdownlist:
ListItem item = new ListItem();
item.Text = "Please select one...";
item.Value = string.Empty; //or whatever value you want to assign to it
item.Selected = true;
drpdownlist.Items.Insert(0, item); //this will insert the item at the top of you list
Let me know if it works.
venkatu2005
All-Star
32487 Points
6742 Posts
Re: How to add "Please select one..." to DropDownList control when it is binding with database?
Nov 04, 2008 03:54 AM|LINK
After binding data from database to Dropdonwlist
set AppendDataboundItems=True
dropdonwlist1.items.insert(0,new listitem("--Select--"))
Thanks.
engineerachu
Contributor
3077 Points
850 Posts
Re: How to add "Please select one..." to DropDownList control when it is binding with database?
Nov 04, 2008 04:39 AM|LINK
Hope this is what you asked:
In Page_Load if(!Page.IsPostBack) { ddlSort.Items.Insert(0, new ListItem("-- Please select One --", "0")); }You should write in (!Page.IsPostBack), or else it will bind again and again when page loads!
Achutha Krishnan