<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" Class="table table-striped table-bordered table-hover"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating"
onrowdatabound="GridView1_RowDataBound">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="checkAll" runat="server" onclick = "checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" onclick = "Check_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reg No.">
<ItemTemplate >
<asp:Label ID="lbl_AdNo" runat="server" Text='<%# Eval("AdmissionNo") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Name">
<ItemTemplate >
<asp:Label ID="Label1" runat="server" Text='<%# Eval("SName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Father Name">
<ItemTemplate >
<asp:Label ID="Label2" runat="server" Text='<%# Eval("FName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subject Name" >
<ItemTemplate >
<asp:Label ID="Label3" runat="server" Text='<%# Eval("SubjectName") %>' Width="75"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Marks" >
<ItemTemplate >
<asp:Label ID="Label4" runat="server" Text='<%# Eval("MaxMarks") %>' Width="75"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pass Marks" >
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("PassMarks") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Marks" >
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("Marks") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="txtMarks" runat="server" Text='<%# Eval("Marks") %>' Width="75"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Edit" ></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update" ></asp:LinkButton>
<asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#CCCCCC" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
and I want to delete selected record and code is :
protected void btnDelete_Click(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
GridViewRow row = GridView1.Rows[i];
CheckBox Chbox = (CheckBox)row.FindControl("CheckBox1");
if (Chbox.Checked == true)
{
select++;
}
}
if (select == 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please Select Record to Delete');", true);
}
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
string AdNo = GridView1.Rows[i].Cells[1].Text;
// Label lbl_AdNo = GridView1.Rows[e.RowIndex].FindControl("lbl_AdNo") as Label;
GridViewRow row = GridView1.Rows[i];
CheckBox Chbox = (CheckBox)row.FindControl("CheckBox1");
if (Chbox.Checked == true)
{
con = new SqlDbConnect();
con.SqlQuery("delete from tblSetMarks where AdmissionNo=@AdNo");
con.Cmd.Parameters.AddWithValue("@AdNo", AdNo);
con.NonQueryEx();
// GridView1.Visible = false;
}
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Student's Marks Deteleted Successfully');", true);
this.BindSectionGrid();
}
This is not deleting the record what is the error in the code