I have a datagrid created programtically(dgAccounts) inside another datagrid(dgHousehold). I have to step through dgB in order to get certain values but then i have to step through dgA in order to get some values from there also.
this is the one i created programtically:
Public Sub dgHousehold_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Try
'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 a new DataGrid object named OrdersDataGrid
Dim dgAccounts As DataGrid = New DataGrid
dgAccounts.DataKeyField = "HouseholdId"
'Format the Datagrid to look how you want it
With dgAccounts
.BorderWidth = Unit.Pixel(1)
.CellPadding = 4
.CellSpacing = 0
.BorderColor = Color.SteelBlue
.Width = Unit.Pixel(300)
.ItemStyle.Font.Name = "Arial"
.ItemStyle.Font.Size = FontUnit.XXSmall
.AlternatingItemStyle.BackColor = Color.LightGray
.ShowHeader = True
.HeaderStyle.BackColor = Color.SteelBlue
.HeaderStyle.ForeColor = Color.White
.HeaderStyle.Font.Bold = True
.HeaderStyle.Font.Size = FontUnit.XXSmall
.AutoGenerateColumns = False
.DataKeyField = "AccountNumber"
End With
'*******Add a series of BoundColumns
'*****AccountNumber*******
Dim bc As BoundColumn = New BoundColumn
'Set the BoundColumn Values
bc.HeaderText = "Account Number"
bc.DataField = "AccountNumber"
bc.ItemStyle.Wrap = False
'Add the BoundColumn to the dgAccounts
dgAccounts.Columns.Add(bc)
'*****InceptionDate*******
bc = New BoundColumn
bc.HeaderText = "Inception Date"
bc.DataField = "InceptionDate"
bc.DataFormatString = "{0:d}"
bc.ItemStyle.Wrap = False
dgAccounts.Columns.Add(bc)
'*****End BoundColumns*****
'Get the Accounts DataView
Dim _accounts As DataView = ds.Tables("Accounts").DefaultView
_accounts.RowFilter = "HouseholdId='" + e.Item.Cells(0).Text + "'"
'Bind the Grid
dgAccounts.DataSource = _accounts
dgAccounts.DataBind()
'Add the dgAccounts to dgHousehold
e.Item.Cells(2).Controls.Add(dgAccounts)
My Question: How do i access the values inside this Datagrid so that i can enter them into the database. Any help will be greatly appreciated. Rest of the code looks like this:
Private Sub cmdEnroll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnroll.Click
Try
Dim strFC As String = ddlFC.SelectedItem.Value
Dim dgItem As DataGridItem
For Each dgItem In dgHousehold.Items
Dim iHouseholdId As Integer = dgHousehold.DataKeys(dgItem.ItemIndex)
>>THIS IS WHERE I WANT TO PUT THE CODE TO STEP THROUGH THE CREATED DATAGRID<<
Next
Catch ex As Exception
lblMessage.Text = "Enrolling: " + ex.Message
End Try
End Sub
this is the one i created programtically:
Public Sub dgHousehold_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Try
'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 a new DataGrid object named OrdersDataGrid
Dim dgAccounts As DataGrid = New DataGrid
dgAccounts.DataKeyField = "HouseholdId"
'Format the Datagrid to look how you want it
With dgAccounts
.BorderWidth = Unit.Pixel(1)
.CellPadding = 4
.CellSpacing = 0
.BorderColor = Color.SteelBlue
.Width = Unit.Pixel(300)
.ItemStyle.Font.Name = "Arial"
.ItemStyle.Font.Size = FontUnit.XXSmall
.AlternatingItemStyle.BackColor = Color.LightGray
.ShowHeader = True
.HeaderStyle.BackColor = Color.SteelBlue
.HeaderStyle.ForeColor = Color.White
.HeaderStyle.Font.Bold = True
.HeaderStyle.Font.Size = FontUnit.XXSmall
.AutoGenerateColumns = False
.DataKeyField = "AccountNumber"
End With
'*******Add a series of BoundColumns
'*****AccountNumber*******
Dim bc As BoundColumn = New BoundColumn
'Set the BoundColumn Values
bc.HeaderText = "Account Number"
bc.DataField = "AccountNumber"
bc.ItemStyle.Wrap = False
'Add the BoundColumn to the dgAccounts
dgAccounts.Columns.Add(bc)
'*****InceptionDate*******
bc = New BoundColumn
bc.HeaderText = "Inception Date"
bc.DataField = "InceptionDate"
bc.DataFormatString = "{0:d}"
bc.ItemStyle.Wrap = False
dgAccounts.Columns.Add(bc)
'*****End BoundColumns*****
'Get the Accounts DataView
Dim _accounts As DataView = ds.Tables("Accounts").DefaultView
_accounts.RowFilter = "HouseholdId='" + e.Item.Cells(0).Text + "'"
'Bind the Grid
dgAccounts.DataSource = _accounts
dgAccounts.DataBind()
'Add the dgAccounts to dgHousehold
e.Item.Cells(2).Controls.Add(dgAccounts)
My Question: How do i access the values inside this Datagrid so that i can enter them into the database. Any help will be greatly appreciated. Rest of the code looks like this:
Private Sub cmdEnroll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnroll.Click
Try
Dim strFC As String = ddlFC.SelectedItem.Value
Dim dgItem As DataGridItem
For Each dgItem In dgHousehold.Items
Dim iHouseholdId As Integer = dgHousehold.DataKeys(dgItem.ItemIndex)
>>THIS IS WHERE I WANT TO PUT THE CODE TO STEP THROUGH THE CREATED DATAGRID<<
Next
Catch ex As Exception
lblMessage.Text = "Enrolling: " + ex.Message
End Try
End Sub