[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

insert "Select..." to dropdownlist


How can I insert initial value "Select..." to dropdownlist?
1. Dropdownlist is in Masterpage, contentplaceholder


For each ctrl as control in Form.controls


 DirectCast(ctrl.FindControl("DropDownList" & y), DropDownList).DataSource = Me.SqlDataSource1
 DirectCast(ctrl.FindControl("DropDownList" & y), DropDownList).Items.Insert(0, "Select...")    <<< this does not help
 DirectCast(ctrl.FindControl("DropDownList" & y), DropDownList).DataTextField = "columnname"
 DirectCast(ctrl.FindControl("DropDownList" & y), DropDownList).DataBind()


next
0
VBdotnet2005
Asked:
VBdotnet2005
2 Solutions
 
Paul JacksonCommented:

Set the AppendDataBoundItems attribute to true and add the default listitem in the aspx :

<asp:DropDownList id="list" runat="server" DataSourceID="dataSource" DataTextField="Name" DataValueField="id" AppendDataBoundItems="true" ><asp:ListItem Text="Select..." Value=0 /></asp:DropDownListItem>

0
 
dejaanbuCommented:
another way is,

after assigning datasource and calling Databind, add this line

Dropdownlist.Items.Insert(0, New ListItem("<<--Select-->>", ""))
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now