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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set SelectedIndex of Datagrid DropDownList

Status
Not open for further replies.

BoydMT

Programmer
May 28, 2003
32
US
When 'Edit' is clicked, I want a drop-down list to display the value that is in the cell prior to clicking 'Edit'. I use the following code to do this:
Code:
Private Sub dgProposals_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgProposals.ItemDataBound
  If e.Item.ItemType = ListItemType.EditItem Then
     'ContactName dropDownList
     Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
     Dim strContact As String = CType(drv("Contact"), String)
     Dim cmbContact As DropDownList = CType(e.Item.FindControl("editContact"), DropDownList)

     Try
         cmbContact.SelectedIndex = cmbContact.Items.IndexOf(cmbContact.Items.FindByText(strContact))
     Catch SQLexc As SqlException
         lblError.Text = "Error while Generating Data.  " & SQLexc.ToString()
     End Try
  End If
End Sub
When 'Edit' is clicked, the drop-down list is blank. What am I missing?

Thanks,
BoydMT
 
The dropdownlist is blank, or there is nothing selected?

-p

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Thanks for the response. I think I resolved the issue by changing the datasource for the drop-down control. I don't believe I was setting the datasource correctly, therefore the control didn't have data to popoulate with.

Thanks again,
BoydMT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top