Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-12
7
Medium Priority
?
265 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

598 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