Link to home
Start Free TrialLog in
Avatar of MikeMCSD
MikeMCSDFlag for United States of America

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.SqlDataReader
      Return Catalog.GetGifts
End Function

<asp:DropDownList ID="ddlGifts" DataSource='<%# FillDropDown %>' DataValueField="GiftID" DataTextField="Event" Runat=server></asp:DropDownList>

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).FindControl("ddlGifts")
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).FindControl("ddlGifts"), DropDownList).SelectedValue
ASKER CERTIFIED SOLUTION
Avatar of ayha1999
ayha1999

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ayha1999
ayha1999

Hi,

You can do the item.insert after binding the dropdownlist in the itembound event.

ayha
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeMCSD

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