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 -
Fir blank first item use below:
ddl.Items.Add(New ListItem(" ", 0))
then use loop to enter items from dataset
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;
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>
精彩评论