Link to home
Start Free TrialLog in
Avatar of convertix
convertix

asked on

Get cell data from a GridView row when checkbox for that row is checked...

I need some help with getting the data from the first cell in the row(s) that are checked in my GridView.

<asp:GridView ID="GVReturns" runat="server" AutoGenerateColumns="False" BorderStyle="Solid"
                                CellPadding="4"  ForeColor="#333333" ShowFooter="True" Width="720px">
                                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <Columns>
                                    <asp:BoundField DataField="ProductID" HeaderText="Product ID" SortExpression="ProductID" />
                                    <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
                                    <asp:BoundField DataField="OrderedProductName" HeaderText="Ordered Product Name" SortExpression="OrderedProductName" />
                                    <asp:BoundField DataField="OrderedProductRegularPrice" HeaderText="Ordered Product Regular Price"
                                        SortExpression="OrderedProductRegularPrice" />
                                    <asp:TemplateField>
                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                        <ItemTemplate>
                                            <asp:CheckBox ID="ReturnItem" runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                               
                                <RowStyle BackColor="#E3EAEB" />
                                <EditRowStyle BackColor="#7C6F57" />
                                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BackColor="White" />
                            </asp:GridView>
Avatar of sandip132
sandip132
Flag of Japan image

Dim dr As GridViewRow
Each dr In GVReturns.Rows
      Dim RowCheckBox As CheckBox = CType(UnBatchedEnquiries.Rows(index).FindControl("RowCheckBox"), CheckBox)
            If RowCheckBox.Checked Then
                '' Get values of your other controls like "Dim RowCheckBox As CheckBox = CType...."
            ElseIf RowCheckBox.Checked = False Then
               '' Nothing
            End If
Next
oops... missed some lines:
Here is the code:

        Dim dr As GridViewRow
        Dim index As Integer = GVReturns.SelectedIndex
        For Each dr In GVReturns.Rows

            If index = -1 Then
                index = 0
            End If
            Dim RowCheckBox As CheckBox = CType(GVReturns.Rows(index).FindControl("RowCheckBox"), CheckBox)
            If RowCheckBox.Checked Then
                '' Get values of your other controls like "Dim RowCheckBox As CheckBox = CType...."
            ElseIf RowCheckBox.Checked = False Then
               '' Nothing
            End If

            index += 1

        Next

Avatar of convertix
convertix

ASKER

Thank you very much!  Please forgive me but I'm not too familiar with GridViews so.....how do I get the data from the first cell in the row(s) that was checked?

If RowCheckBox.Checked Then
                '' Get values of your other controls like "Dim RowCheckBox As CheckBox = CType...."  <----- I would assume this "get cell" code would go here?
            ElseIf RowCheckBox.Checked = False Then
               '' Nothing
            End If
ASKER CERTIFIED SOLUTION
Avatar of badalpatel
badalpatel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial