all groups > asp.net datagrid control > april 2008 >
You're in the

asp.net datagrid control

group:

Programmatically adding Datagrids to PlaceHolder


Programmatically adding Datagrids to PlaceHolder DanG
4/15/2008 2:09:59 PM
asp.net datagrid control:
I have a dataset with multiple "groups", and I want each group to
appear in its own datagrid. As I step through the code, it runs just
as I want, with the appropriate records being added to each grid, and
the grid goes into the PlaceHolder. I can even check the controls in
the placeholder to confirm the correct grid data is there.

But when I release control to the screen, all grids have the same
contents, which match the records in the LAST dataview. How do I get
the grids to display the correct data?

Thanks



Private Sub BuildGrids()
DsGroups1 = cData.GetAllGroups(167)

Dim group As String
Dim dr As dsGroups.DetailRow
For Each dr In DsGroups1.Detail.Rows
If dr.group <> group Then
Dim dg As New DataGrid

Dim dv As New DataView
dv = DsGroups1.Detail.DefaultView
dv.RowFilter = String.Format("group = '{0}'",
dr.group)

dg.AutoGenerateColumns = True
dg.DataSource = dv
dg.DataBind()

plhGroups.Controls.Add(dg)
group = dr.group
End If
Next

AddThis Social Bookmark Button