How can I set the initial value of a drop downlis开发者_开发百科t say to the word "Empty"..regardless to what i bind to it in the pageload or feed values dynamically
You should add this item manually and set the DropDownList's AppendDataBoundItems property to true
.
For example (added on ASPX):
<asp:DropDownList ID="DropDownList1" runat="server"
AppendDataBoundItems="true"
DataSource="myDataSource"
DataTextField="TextColumn"
DataValueField="IdColumn">
<asp:ListItem Text="Empty..." Value="0" Selected="True"></asp:ListItem>
</asp:DropDownList>
or in codebehind:
DropDownList1.Items.Add(New ListItem("Empty...", "0", True))
DropDownList1.DataTextField = "TextColumn"
DropDownList1.DataValueField = "IdColumn"
DropDownList1.DataSource = myDataSource
DropDownList1.DataBind()
Just create an new list item and then add it to the Drop Down. Do it in the Page_load function or data bind.
var emptyvalue = new ListItem("Empty...", "0");
DropDownItem.Items.Add(emptyvalue );
Try This :
DrpDwn_ProductType.Items.Insert(0, new ListItem("-- Empty...", ""));
精彩评论