Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SelectedValue property of DropDownList in DataGrid 1

Status
Not open for further replies.

phbrady

Programmer
Oct 17, 2003
41
US
I have a dropdownlist which I have added to a datagrid. I can populate the list no problem, but how do I set the SelectedValue? The only property I see available in the HTML view is SelectedIndex, which doesn't really help if I'm trying to select the item in the list based on the value from the database.

Thanks in advance!
 
You have to get a refence to the dropdown list in the itemdatabound event.
Something like:
Code:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim ddl As New DropDownList
            ddl = e.Item.FindControl("YourddlName")
            ddl.SelectedValue = ("somevalue")
        End If
    End Sub

Jim
 
Bingo! That works beautifully, jbenson.

Thanks,
pb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top