Question : access gridview checkbox and rotate though rows to save

Finally upgrading to 3.5 but things are little different, what I am doing is using a updatepannel for ajax functionality and trying to access the checkbox to see if checked and then save data to a db but I get an error on this.

in the javascript error it tell me that
sys.webforms.pagerequestmanagerservererrorexception: unable to cast direct of type "System.ui.webcontrols.gridviewRow to type system.web.ui.webcontols.gridview.

Belwo is how I used to access a chcekbox in 1.1 but I think i am doing something wrong.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <table width="100%" id="tblGrid" style="display:none">
                        <tr>
                            <td align="center">
                                <asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="false" HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" CellSpacing="5" BorderStyle="Solid" BorderWidth="1" BorderColor="blue">
                                    <Columns>
                                        <asp:TemplateField HeaderText="Delete">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="cbDelete" runat="server" AutoPostBack="false" CausesValidation="false" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="intBenchMark" HeaderText="SID" />
                                        <asp:BoundField DataField="strBenchMarkname" HeaderText="Name" />
                                    </Columns>
                                </asp:GridView>
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <a onclick="javascript:cancelBenchMarks();" style="cursor:hand;color:Blue;text-decoration:underline;">cancel</a>
                                 &nbsp;&nbsp;&nbsp;<asp:LinkButton ID="lnkSave" runat="server">submit</asp:LinkButton>
                           </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>

Protected Sub lnkSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSave.Click
        For Each dgi As GridView In myGridView.Rows
            Dim Sid As Integer = Convert.ToInt32(dgi.Columns(1).ToString)
            Dim cb As CheckBox = DirectCast(dgi.FindControl("cbDelete"), CheckBox)

            If cb.Checked = True Then
                sql = "Delete from tblBenchMarkname where intSid = " & Sid
                Response.Write(sql)
                Response.End()
                insertUpdateDelete(sql)
            End If

        Next

    End Sub

Answer : access gridview checkbox and rotate though rows to save

This should be as

For Each dgi As GridView In myGridView.Rows

Correct
For Each dgi As GridViewRow In myGridView.Rows
Random Solutions  
 
programming4us programming4us