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

Bind data to a drop down in a datagrid

Status
Not open for further replies.

Bodhi147

MIS
Jan 24, 2003
17
US
I have a drop down box that is dynamically populated from other user defined criteria. I want this drop down to appear in a datagrid on the same page. Is there a way to populate a datagrid drop down using data from another drop down outside the grid? Some guidance would be greatly appreciated. Thank you
 
sure, the steps:
1. Bind datagrid.
2. use a for loop and read through each row.
3. identify the column that holds the dropdown (u should already know that).
4. get the column's control(FindControl() method) and convert it into a dropdown control using CTYPE.
5. populate content.

Known is handfull, Unknown is worldfull
 
Code:
Private Sub dtGoals_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dtGoals.ItemDataBound
 If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
  'Initialize all the controls for the item
  Dim ddRating As DropDownList = CType(e.Item.FindControl("ddRating"), DropDownList)
  Dim gd As New HRReviewBL.StaffGoals

  ddRating.DataSource = gd.LoadRatings
  ddRating.DataValueField = "ratingID"
  ddRating.DataTextField = "rating"
  ddRating.DataBind()
  ddRating.Items.Insert(0, New ListItem("< Select >", 0))
  ddRating.Dispose()
 End If
End Sub

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top