Datagrid Combobox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've created a combobox in a datagrid, it works OK using the code where
"supplier1" and "supplier2" are the items. However, instead of using hard
coded items, I want to use data obtained from the dataset DsSupplier1. Any
help would be most appreciated.

SqlDataSupplier.Fill(DsSupplier1)

suppcombo.Name = "Suppcombo"
suppcombo.Visible = False
suppcombo.Items.Clear()
suppcombo.Items.Add("supplier1")
suppcombo.Items.Add("Supplier2")
DataGrid1.Controls.Add(suppcombo)
 
Hi there,

What you need to do is handle the datagrid's ItemDataBound event. The event
argument will contain the datagrid Item. Check the type of the item so you
can populate it only when you need to, and databind the combo box
programmatically. E.g:

Private Sub sample_ItemDataBound(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles sample.ItemDataBound

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
Dim ddList As DropDownList
ddList = CType(e.Item.Cells(3).Controls(1), DropDownList)
ddList.DataSource = MyDataSource
ddList.DataBind()
End Select

End Function

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top