W
wsyeager36
I have a datagrid inside a datalist. The datalist shows parent info and the datagrid shows the child info for that parent. There is a checkbox on each row of the child datagrid. Also inside the datalist is a radiobuttonlist. When this radiobuttonlist is checked, I would like it to iterate thru each row on the child grid and either select or deselct the checkboxes (which are on each row of the child datagrid). In addition, the user can also check each of these checkboxes individually as well. btw, I made the columns that I need to access inside the datagrid template columns. For the rows that are checked, I want to save them to a dataset.
I created code below to do the above task:
Private Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged
'Capture the postback event from the radiobuttonlist
Dim rblConditions As RadioButtonList = DirectCast(FindControl("RadioButtonList1"), RadioButtonList)
Dim dg2 As DataGrid = DirectCast(FindControl("DataGrid2"), DataGrid)
Dim chkCondition As CheckBox = DirectCast(FindControl("Condition"), CheckBox)
Dim lblLockNumber As Label = DirectCast(FindControl("LockNumber"), Label)
Dim lblConditionDetailID As Label = DirectCast(FindControl("ConditionDetailID"), Label)
Dim lblLoanID As Label = DirectCast(FindControl("LoanID"), Label)
Dim i As Int16
If rblConditions.SelectedIndex = YesNoIndex.YES Then
'check all the boxes in the child datagrid
For i = 0 To dg2.Items.Count - 1
chkCondition.Checked = True
Next
Else
'uncheck all the boxes in the child datagrid
For i = 0 To dg2.Items.Count - 1
chkCondition.Checked = False
Next
End If
For i = 0 To dg2.Items.Count - 1
If chkCondition.Checked = True Then
Dim drSave As dsSaveCondition.dsSaveConditionRow = DsSaveCondition1.dsSaveCondition.NewdsSaveConditionRow
drSave.Lock_Number = lblLockNumber.Text
drSave.ConditionDetailID = lblConditionDetailID.Text
drSave.LoanID = lblLoanID.Text
DsSaveCondition1.dsSaveCondition.Rows.Add(drSave)
End If
Next
If ViewState.Item("DsSaveCondition1") Is Nothing Then
DsSaveCondition1.AcceptChanges()
Else
DsSaveCondition1 = DirectCast(ViewState.Item("DsSaveCondition1"), DataSet)
End If
ViewState.Item("DsSaveCondition1") = DsSaveCondition1
End Sub
Since I won't be able to test this out until Monday, I'm wondering if the above code is "on target". I'm unsure of how to handle the postback event from the radiobuttonlist (autopostback is set to TRUE) which is inside the datalist as well as cycling thru the datagrid rows to check or uncheck the boxes.
Can someone please tell me if I need to do anything else?
Your help is greatly appreciated...
**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
I created code below to do the above task:
Private Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged
'Capture the postback event from the radiobuttonlist
Dim rblConditions As RadioButtonList = DirectCast(FindControl("RadioButtonList1"), RadioButtonList)
Dim dg2 As DataGrid = DirectCast(FindControl("DataGrid2"), DataGrid)
Dim chkCondition As CheckBox = DirectCast(FindControl("Condition"), CheckBox)
Dim lblLockNumber As Label = DirectCast(FindControl("LockNumber"), Label)
Dim lblConditionDetailID As Label = DirectCast(FindControl("ConditionDetailID"), Label)
Dim lblLoanID As Label = DirectCast(FindControl("LoanID"), Label)
Dim i As Int16
If rblConditions.SelectedIndex = YesNoIndex.YES Then
'check all the boxes in the child datagrid
For i = 0 To dg2.Items.Count - 1
chkCondition.Checked = True
Next
Else
'uncheck all the boxes in the child datagrid
For i = 0 To dg2.Items.Count - 1
chkCondition.Checked = False
Next
End If
For i = 0 To dg2.Items.Count - 1
If chkCondition.Checked = True Then
Dim drSave As dsSaveCondition.dsSaveConditionRow = DsSaveCondition1.dsSaveCondition.NewdsSaveConditionRow
drSave.Lock_Number = lblLockNumber.Text
drSave.ConditionDetailID = lblConditionDetailID.Text
drSave.LoanID = lblLoanID.Text
DsSaveCondition1.dsSaveCondition.Rows.Add(drSave)
End If
Next
If ViewState.Item("DsSaveCondition1") Is Nothing Then
DsSaveCondition1.AcceptChanges()
Else
DsSaveCondition1 = DirectCast(ViewState.Item("DsSaveCondition1"), DataSet)
End If
ViewState.Item("DsSaveCondition1") = DsSaveCondition1
End Sub
Since I won't be able to test this out until Monday, I'm wondering if the above code is "on target". I'm unsure of how to handle the postback event from the radiobuttonlist (autopostback is set to TRUE) which is inside the datalist as well as cycling thru the datagrid rows to check or uncheck the boxes.
Can someone please tell me if I need to do anything else?
Your help is greatly appreciated...
**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...