goofyui
goofyui

Reputation: 3492

Dropdownlist Box - C#

I have a very basic syntax question on Populating a dropdownlist box from dataset. I want the first column or Dropdownlistbox.selectedIndex(-1) = "" .

i.e) First Column Should be Empty - Instead of - SELECT -

Upvotes: 0

Views: 332

Answers (3)

Steve Wellens
Steve Wellens

Reputation: 20640

If you are binding from a collection: Set it up like this (note AppendDataBoundItems...)

   <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True">
    <asp:ListItem Value="-1"></asp:ListItem>
</asp:DropDownList>

Upvotes: 1

Saurabh
Saurabh

Reputation: 5727

Fir blank first item use below:

ddl.Items.Add(New ListItem(" ", 0)) 

then use loop to enter items from dataset

Upvotes: 1

Ovais Khatri
Ovais Khatri

Reputation: 3211

suppose dt is the table with data....having col1 as value column and col2 as Display column, DataRow dr = dt.NewRow(); dr[0] ="-1"; dr[1] = " ";

dt.Rows.InsertAt(row,0);

ddl.DataSource = dt;

Upvotes: 1

Related Questions