MikeMCSD
asked on
Make an item's value equal zero in drop down list
I added an item to a drop down list located in a DataGrid in the ItemDataBound event.
The drop down list is first populated from the database like this:
Public Function FillDropdown() As System.Data.SqlClient.SqlD ataReader
Return Catalog.GetGifts
End Function
<asp:DropDownList ID="ddlGifts" DataSource='<%# FillDropDown %>' DataValueField="GiftID" DataTextField="Event" Runat=server></asp:DropDow nList>
I need to set its VALUE to zero so I can check for this value later.
This works but it doesn't set it's VALUE to zero:
Private Sub productsGrid_ItemDataBound
.....................
Dim ddl As DropDownList
ddl = e.Item.Cells(1).FindContro l("ddlGift s")
ddl.Items.Insert(0, "Select Gift Category") << need to make the Value = 0
Right now, this (Gift) equals "Select Gift Category" not zero, which I need:
Dim Gift As String = CType(e.Item.Cells(1).Find Control("d dlGifts"), DropDownList).SelectedValu e
The drop down list is first populated from the database like this:
Public Function FillDropdown() As System.Data.SqlClient.SqlD
Return Catalog.GetGifts
End Function
<asp:DropDownList ID="ddlGifts" DataSource='<%# FillDropDown %>' DataValueField="GiftID" DataTextField="Event" Runat=server></asp:DropDow
I need to set its VALUE to zero so I can check for this value later.
This works but it doesn't set it's VALUE to zero:
Private Sub productsGrid_ItemDataBound
.....................
Dim ddl As DropDownList
ddl = e.Item.Cells(1).FindContro
ddl.Items.Insert(0, "Select Gift Category") << need to make the Value = 0
Right now, this (Gift) equals "Select Gift Category" not zero, which I need:
Dim Gift As String = CType(e.Item.Cells(1).Find
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ayha . . thanks!!!!!!! works perfect
I was trying to find how to use the ListItem in code but just couldn't get it.
sam, thanks, that would have worked also
I was trying to find how to use the ListItem in code but just couldn't get it.
sam, thanks, that would have worked also
You can do the item.insert after binding the dropdownlist in the itembound event.
ayha