Would it not be better to fire a event when they check the box, or "change" the radio button list?
In fact, would not just clicking on that row make sense to trigger display of the other “div” with the grid that displays information based on the current row from the grid?
In other words?
Clicking on the grid row.
Or clicking on the check box on that grid row.
Or clicking on the radio button “list” on that grid row?
Does not all of the above warrant that we really just want the “show details” event to trigger in all of the above cases?
So, if they click on a row – then we trigger the detail display. And if while on that row, if we click the text box, or the radio button list – once again our event should fire.
And of course if they click on a check box (or radio button) on a differ row, then we need that control to change and THEN AGAIN fire our display list. So we want the 2nd event + display to follow the above design (at least I think we do???)
So, it seems to me our goal is:
Clicking on a row – be it the result of clicking on a check box radio button or “just” on the row – we need to get that row information and “send” it to our second display grid (or whatever it may be). That way, a user can click on any row - our details (other grid or whatever) will now display.
Ok,
So, lets first use a neat-o trick to get the row index changed event to fire ALWAYS WHEN we click on that row (don’t matter if check box, don’t matter if radio button list, don’t matter if any place else on the row). (we can pick up the values anyway)
So, in our row data bound event, we can add this little gem. (it’s a bit ugly), but ONCE done, then we can just write easy pure code to deal with EVERYTHING else!
Ok, so in our row data bound, we add this to ALWAYS ensure that the selected index changed event fires.
That magic act, that Rosetta stone, that miracle? That of having Santa Clause climb down the chimney and give you presents?
We do this:
Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes("onclick") =
Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Select$" & e.Row.RowIndex)
e.Row.ToolTip = "Click to select this row."
End If
End Sub
So now, we have the all valuable "index change" event to fire anytime we click on a row.
Now the Christmas present time.
It turns out that even if you click on the row again the index change fires. So, clicking anywhere - and that includes the radio button, or check box? Our index change event fires!! and that is EXACTLY what we need and want.
So, now we just move ALL of our "update/display/show/fill/" of that 2nd grid areas display.
Our code now becomes this because that all important index change fires:
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
' get selected index of row selected
Dim ixRow As Integer = GridView1.SelectedIndex
Debug.Print("sel grid index row = " & ixRow)
' (might not need the above, but with index into grid
' - the world is at your beck and call
' get current grid row:
Dim gv As GridViewRow = GridView1.SelectedRow
' (we we could I suppose use GridView1.Rows(ixRow)
' now get Radio button value:
Dim MyRadioList As RadioButtonList = gv.FindControl("RadioButtonlist1")
Debug.Print("Radio selection value = " & MyRadioList.SelectedValue)
Debug.Print("Radio selection index = " & MyRadioList.SelectedIndex)
' get the check box value
Dim MyCheckBox As CheckBox = gv.FindControl("CheckBox1")
Debug.Print("check box value = " & MyCheckBox.Checked)
' code here to update your 2nd display
' walk the dog - do whatever you want
' Call displayInfo2(gv)
End Sub
if anything changes - such as the radio button, or the check box, our index event will fire again - and does so even if the Radio button list and the check box on that row changes - again just what the doctor ordered.
This also means we toss out all kinds of looping code.
So now, Bob is your uncle!