Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have dropdownlist & i am binding my datatable values to it.

C#
ddlMName.DataSource = objDS.Tables[0];
ddlMName.DataTextField = "MenuName";
ddlMName.DataValueField = "MenuID";
ddlMName.DataBind();
with addition of this i need to bind the following value to it
ddlMName.Items.Add(new ListItem("<<Select One>>", "-1"));


<<select one>> should display in dropdownlist at first & then datatable values.


How can i do this?
Posted
Updated 16-Apr-12 21:48pm
v2

Hi ,
try this one ,
You have to set AppendDataBoundItems = True
ASP.NET
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True">
    <asp:ListItem Value="-1">--select on --</asp:ListItem>
</asp:DropDownList>

Best Regards
M.Mitwalli
 
Share this answer
 
try this way

C#
drpList.Items.Insert(0, new ListItem(String.Empty, "<<Select One>>"));
drpList.SelectedIndex = 0;


http://stackoverflow.com/questions/267064/asp-net-add-blank-item-at-top-of-dropdownlist[^]
 
Share this answer
 
v2
As You Want Value Of
"<<Select One>>" is -1

You Can Do Like This(Small Change Is Sollution1)
C#
drpList.Items.Insert(0, new ListItem("<<Select One>>","-1"));

Where The Arguments are As
SQL
drpList.Items.Insert(index value,New ListItem(Text As String, Value As string))
 
Share this answer
 
v2
just replace this code line
C#
ddlMName.Items.Add(new ListItem("<<Select One>>", "-1"));

to this code of line
C#
ddlMName.Items.Insert(0, new ListItem("Select One", "0"));
 
Share this answer
 
v2
try this it may help for you
DropdownList1.Items.Insert(0, new ListItem("--Select One--", "0"));
 
Share this answer
 
v3

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