?
Solved

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

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

Technology Partners: 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

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…
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 …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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