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

Discussion in 'ASP .Net Datagrid Control' started by partybob99@hotmail.com, Apr 5, 2006.

  1. Guest

    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
    , Apr 5, 2006
    #1
    1. Advertising

  2. 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)

    <> escreveu na mensagem
    news:...
    >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
    >
    Bruno Alexandre, Apr 6, 2006
    #2
    1. Advertising

  3. Guest

    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
    , Apr 6, 2006
    #3
  4. Teemu Keiski Guest

    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.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    <> wrote in message
    news:...
    > 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
    >
    Teemu Keiski, Apr 8, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Davidson
    Replies:
    0
    Views:
    419
    Mark Davidson
    Aug 11, 2003
  2. =?Utf-8?B?UmljaGFyZEg=?=

    Checkbox and dropdownlist row in repeater row

    =?Utf-8?B?UmljaGFyZEg=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    6,374
    =?Utf-8?B?UmljaGFyZEg=?=
    Mar 24, 2006
  3. sauce
    Replies:
    0
    Views:
    230
    sauce
    Apr 12, 2005
  4. D
    Replies:
    0
    Views:
    206
  5. asp123 vbnet via .NET 247

    Adding Checkboxlist/checkbox to dataGrid and retrieving selected value

    asp123 vbnet via .NET 247, Mar 25, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    624
    asp123 vbnet via .NET 247
    Mar 25, 2005
Loading...

Share This Page