Solved

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

Posted on 2006-11-12
7
251 Views
Last Modified: 2008-03-06
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>
0
Comment
Question by:convertix
  • 2
7 Comments
 
LVL 12

Expert Comment

by:sandip132
Comment Utility
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
0
 
LVL 12

Expert Comment

by:sandip132
Comment Utility
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

0
 

Author Comment

by:convertix
Comment Utility
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
0
 
LVL 6

Accepted Solution

by:
badalpatel earned 500 total points
Comment Utility
hello
u can try the following codeto get the first value of cell..
             
  If GRIDVIEW_OTHEREVENT.Rows.Count > 0 Then
                        For i = 0 To GRIDVIEW_OTHEREVENT.Rows.Count - 1
                            Dim row As GridViewRow = GRIDVIEW_OTHEREVENT.Rows(i)
                            Dim ischecked As Boolean
                            ischecked = CType(row.FindControl("chkChecked"), CheckBox).Checked
                            If ischecked = True Then
                            'if checkbox is selected then get the first cell value in variable
                            dim str as string =CType(GRIDVIEW_OTHEREVENT.Rows(i).Cells(0).FindControl("ProductID"), Label).Text
                             End If
                           Next
                    End If
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now