Solved

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

Posted on 2006-11-12
7
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 12

Expert Comment

by:sandip132
ID: 17928236
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
ID: 17928245
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
ID: 17928284
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
ID: 17928339
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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