This can be done one of 2 ways. A default ListItem can be added to a DropDownList programmatically with the following syntax after binding data to the DropDownList:
//Code here to populate DropDownList
DropDownListID.Items.Insert(0, new ListItem("Default text", "Default value")
This will add a ListItem to index 0, which will be the first ListItem.
In .NET 2.0, this can be done declaratively using the AppendDataBoundItems property. This will append
all data-bound ListItems to the DropDownList, leaving those you add manually as the first selections.
Sunil Baghel
Member
1 Points
7 Posts
How can display static data in drop down list from aspx.cs page
Nov 17, 2012 09:07 AM|LINK
hi,
how i can dispaly drop down list static Items from aspx.cs Page, i tried below:
DropDownList15.SelectedItem.Text = "Weekly Off", "Present";
but i am getting some error.
Please help any one.
graciax8
Participant
751 Points
210 Posts
Re: How can display static data in drop down list from aspx.cs page
Nov 17, 2012 09:29 AM|LINK
in your aspx page
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Weekly Off</asp:ListItem>
<asp:ListItem>Present</asp:ListItem>
</asp:DropDownList>
mycodepad.blogspot.com || TUMBLR
Sunil Baghel
Member
1 Points
7 Posts
Re: How can display static data in drop down list from aspx.cs page
Nov 17, 2012 09:47 AM|LINK
i know above, but i want to display same item from aspx.cs page .Please.
graciax8
Participant
751 Points
210 Posts
Re: How can display static data in drop down list from aspx.cs page
Nov 17, 2012 10:03 AM|LINK
dropdownlist1.items.add("week off")
mycodepad.blogspot.com || TUMBLR
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How can display static data in drop down list from aspx.cs page
Nov 18, 2012 01:00 AM|LINK
Hello,
Please try this:
Response.Write(DropDownList15.SelectedItem.ToString());
Sunil Baghel
Member
1 Points
7 Posts
Re: How can display static data in drop down list from aspx.cs page
Nov 18, 2012 11:03 AM|LINK
but where i can mention items ???which i want to display in dropdown list
Sunil Baghel
Member
1 Points
7 Posts
Re: How can display static data in drop down list from aspx.cs page
Nov 18, 2012 11:07 AM|LINK
this would be add one item on every selection...........
RameshRajend...
Star
7983 Points
2099 Posts
Re: How can display static data in drop down list from aspx.cs page
Nov 18, 2012 12:32 PM|LINK
Hai
This can be done one of 2 ways. A default ListItem can be added to a DropDownList programmatically with the following syntax after binding data to the DropDownList:
//Code here to populate DropDownList
DropDownListID.Items.Insert(0, new ListItem("Default text", "Default value")
This will add a ListItem to index 0, which will be the first ListItem.
In .NET 2.0, this can be done declaratively using the AppendDataBoundItems property. This will append all data-bound ListItems to the DropDownList, leaving those you add manually as the first selections.
<asp:DropDownList ID="DropDownListID" AppendDataBoundItems="true" runat="server">
<asp:ListItem Text="Default text" Value="Default value" />
</asp:DropDownList>
and
Please check this
http://forums.asp.net/t/1375726.aspx/1
http://forums.asp.net/t/1142484.aspx/1