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="OrderedProductN ame" HeaderText="Ordered Product Name" SortExpression="OrderedPro ductName" />
<asp:BoundField DataField="OrderedProductR egularPric e" HeaderText="Ordered Product Regular Price"
SortExpression="OrderedPro ductRegula rPrice" />
<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>
<asp:GridView ID="GVReturns" runat="server" AutoGenerateColumns="False
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="OrderedProductN
<asp:BoundField DataField="OrderedProductR
SortExpression="OrderedPro
<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>
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 ).FindCont rol("RowCh eckBox"), 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
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
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Each dr In GVReturns.Rows
Dim RowCheckBox As CheckBox = CType(UnBatchedEnquiries.R
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