Need Help retrieving row # from asp.net datagrid using checkbox

P

partybob99

I am working with a datagrid in asp.net and I added an itemtemplate to
place a checkbox in every row. The code looks like this (aspx page)

<asp:TemplateColumn HeaderText="Select"><HeaderStyle
Width="2%"></HeaderStyle>
<ItemTemplate>
<table align="center">
<asp:CheckBox ID="SELECT" Font-size="8" OnCheckedChanged="test"
runat="server" />
</table>
</ItemTemplate>
</asp:TemplateColumn>

When the user clicks on the check box and then clicks the submit button
the program will post the event to the "test" procedure I've set up.
If the user changes the state of the checkbox on multiple rows, the
"test" procedure will fire once for every checkbox state that has
changed.

My question is: In the procedure "test", how do I get the row number
the checkbox belongs to in the datagrid? I actually need to get a
number values from the row itself, but if I could get the row number
that would be enough that I could figure out the rest of it.

Thanks in advance
 
B

Bruno Alexandre

You can only know if you use the DataGrid Event Arguments...

but why not calling the function test with the ID value of the row ?


<asp:CheckBox ID="SELECT" Font-size="8" OnCheckedChanged="test( <%=
Eval("idFromDatabase") %> )"
runat="server" />



Public Function Test( rowValue as String )

End Function

--


Thank you in Advance.

Bruno Alexandre
(a Portuguese in Denmark)
 
P

partybob99

Thanks Bruno. I did not use your suggestion directly, but it gave me
an idea. After some work I figured out that I could use the sender
object passed into the event to derive the parent, and then from that
parent derive another parent to get the values I need to ID the record
successfully.

Here is my example:
Sub test _
(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim cb As CheckBox = CType(sender, CheckBox)
Dim strWorkOrder As String = _
CType(cb.Parent.Parent.Controls(2), TableCell).Text

I can access the table cells directly using this syntax. There might
be an easier way, but this seems to do the job.

Bob
 
T

Teemu Keiski

Hi,

you also get the DataGridItem by getting NamingContainer property from the
CheckBox, and casting that to DataGridItem. That prepresents the current row
in DataGrid.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top