I've got 2 datagrids, one nested in the other. The nested datagrid has 2 columns, the 2nd is a templated column which is to use the value of the 1st bound column.
Can anyone help me to figure this out.
My code to nest the 2nd datagrid is as follows and I don't know how to use the value of the bound column, filename, to set as the text in the templated column which is created by using a user control:
Protected Sub dgParts_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
'When each row is created in the DataGrid, eval the ItemType
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
'If the ItemType is Item or AlternatingItem, create the photos dataGrid
Dim dgPhotos As DataGrid = New DataGrid()
'Add BoundColumn
Dim bc As BoundColumn = New BoundColumn()
'Set the BoundColumn Values
bc.HeaderText = ""
bc.DataField = "filename"
bc.ItemStyle.Wrap = False
'Add the BoundColumn to the dgPhotos.
dgPhotos.Columns.Add(bc)
'Add Templatecolumn
Dim temp As ITemplate = Page.LoadTemplate("Controls/photos_control.ascx"
Dim tc As TemplateColumn = New TemplateColumn()
tc.HeaderText = "filename"
tc.ItemTemplate = temp
dgPhotos.Columns.Add(tc)
'Get the photos DataView and filter it for the current Part ID
Dim _photos As DataView = ds.Tables("Photos".DefaultView
_photos.RowFilter = "parts_id='" & e.Item.Cells(0).Text & "'"
'Bind the DataGrid.
dgPhotos.DataSource = _photos
dgPhotos.DataBind()
'Add the dgPhotos to the BooksDataGrid.
e.Item.Cells(2).Controls.Add(dgPhotos)
End If
End Sub
The control in photos_control.ascx is a label of which the text must be the value of the bound column.
Any help would be greatly appreciated.
Can anyone help me to figure this out.
My code to nest the 2nd datagrid is as follows and I don't know how to use the value of the bound column, filename, to set as the text in the templated column which is created by using a user control:
Protected Sub dgParts_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
'When each row is created in the DataGrid, eval the ItemType
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
'If the ItemType is Item or AlternatingItem, create the photos dataGrid
Dim dgPhotos As DataGrid = New DataGrid()
'Add BoundColumn
Dim bc As BoundColumn = New BoundColumn()
'Set the BoundColumn Values
bc.HeaderText = ""
bc.DataField = "filename"
bc.ItemStyle.Wrap = False
'Add the BoundColumn to the dgPhotos.
dgPhotos.Columns.Add(bc)
'Add Templatecolumn
Dim temp As ITemplate = Page.LoadTemplate("Controls/photos_control.ascx"
Dim tc As TemplateColumn = New TemplateColumn()
tc.HeaderText = "filename"
tc.ItemTemplate = temp
dgPhotos.Columns.Add(tc)
'Get the photos DataView and filter it for the current Part ID
Dim _photos As DataView = ds.Tables("Photos".DefaultView
_photos.RowFilter = "parts_id='" & e.Item.Cells(0).Text & "'"
'Bind the DataGrid.
dgPhotos.DataSource = _photos
dgPhotos.DataBind()
'Add the dgPhotos to the BooksDataGrid.
e.Item.Cells(2).Controls.Add(dgPhotos)
End If
End Sub
The control in photos_control.ascx is a label of which the text must be the value of the bound column.
Any help would be greatly appreciated.