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_Selec tedIndexChanged (ByVal sender As Object, ByVal e As System.EventArg s) Handles DataList1.Selec tedIndexChanged
'Capture the postback event from the radiobuttonlist
Dim rblConditions As RadioButtonList = DirectCast(Find Control("RadioB uttonList1"), RadioButtonList )
Dim dg2 As DataGrid = DirectCast(Find Control("DataGr id2"), DataGrid)
Dim chkCondition As CheckBox = DirectCast(Find Control("Condit ion"), CheckBox)
Dim lblLockNumber As Label = DirectCast(Find Control("LockNu mber"), Label)
Dim lblConditionDet ailID As Label = DirectCast(Find Control("Condit ionDetailID"), Label)
Dim lblLoanID As Label = DirectCast(Find Control("LoanID "), Label)
Dim i As Int16
If rblConditions.S electedIndex = YesNoIndex.YES Then
'check all the boxes in the child datagrid
For i = 0 To dg2.Items.Count - 1
chkCondition.Ch ecked = True
Next
Else
'uncheck all the boxes in the child datagrid
For i = 0 To dg2.Items.Count - 1
chkCondition.Ch ecked = False
Next
End If
For i = 0 To dg2.Items.Count - 1
If chkCondition.Ch ecked = True Then
Dim drSave As dsSaveCondition .dsSaveConditio nRow = DsSaveCondition 1.dsSaveConditi on.NewdsSaveCon ditionRow
drSave.Lock_Num ber = lblLockNumber.T ext
drSave.Conditio nDetailID = lblConditionDet ailID.Text
drSave.LoanID = lblLoanID.Text
DsSaveCondition 1.dsSaveConditi on.Rows.Add(drS ave)
End If
Next
If ViewState.Item( "DsSaveConditio n1") Is Nothing Then
DsSaveCondition 1.AcceptChanges ()
Else
DsSaveCondition 1 = DirectCast(View State.Item("DsS aveCondition1") , DataSet)
End If
ViewState.Item( "DsSaveConditio n1") = DsSaveCondition 1
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...