handling an event for a control embedded in a datalist

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...
 
B

bill

I know the datalist can respond to events from child
button controls via the ITEMCommand event, etc of the
Datalists ItemCommand event. But, can the datalist handle
events such as the one I have outlined in the previous
message, particularly selecting a child radiobutton
inside the datalist, posting the page back and responding
to which radiobutton was checked (inside the datalist)
and then programmatically selecting check boxes on a
child datagrid within the datalist.

I presently have the code to do this inside
the "DataList1_SelectedIndexChanged" event (as described
in my previous msg). If this is not the case, I would
then try to place the code inside an event that I would
set up in the HTML as follows for the radiobuttonlist:
OnSelectedIndexChanged="rblRadioButtonList1_SelectedIndexC
hanged"

I then would have an event in code-behind which will
handle this:
Protected WithEvents RadioButtonList1 As RadioButtonList
..
..
..
Private Sub rblRadioButtonList1_SelectedIndexChanged
(ByVal sender As Object, ByVal e As System.EventArgs)
Handles RadioButtonList1.SelectedIndexChanged

Can someone please tell me if I'm target with this?
-----Original Message-----
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top