My apsx
<section class="sec1" style="height:100vh;">
<link href="../Css/masterStyle.css" rel="stylesheet" />
<link href="../Css/cartStyle.css" rel="stylesheet" />
<h1>Cart</h1>
<p class="sec1_p1">Your Food</p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableTheming="True" ShowFooter="True" OnRowDeleting="GridView1_RowDeleting" >
<Columns>
<asp:BoundField DataField="sno" HeaderText="sno" Visible="False" />
<asp:BoundField DataField="restaurantID" HeaderText="restaurantID" Visible="False" />
<asp:BoundField DataField="foodID" HeaderText="foodID" Visible="False">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="foodName" HeaderText="Name">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="foodPrice" HeaderText="Price">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="quantity" HeaderText="Quantity">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="totalPrice" HeaderText="Total ">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:CommandField DeleteText="Remove" ShowDeleteButton="True" />
</Columns>
<HeaderStyle BackColor="#52E770" ForeColor="White" />
</asp:GridView>
<asp:Label ID="test" runat="server" Text="Label"></asp:Label>
</section>
My .cs
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataTable dt = new DataTable();
dt = (DataTable)Session["buyitems"];
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
int sr;
int sr1;
string qdata;
string dtdata;
sr = Convert.ToInt32(dt.Rows[i]["sno"].ToString());
TableCell cell = GridView1.Rows[e.RowIndex].Cells[0];
qdata = cell.Text;
dtdata = sr.ToString();
sr1 = Int32.Parse(qdata); //fixed
if (sr == sr1)
{
dt.Rows[i].Delete();
dt.AcceptChanges();
//Label1.Text = "Item Has Been Deleted From Shopping Cart";
break;
}
}
for (int i = 1; i <= dt.Rows.Count; i++)
{
dt.Rows[i - 1]["sno"] = i;
dt.AcceptChanges();
}
Session["buyitems"] = dt;
Response.Redirect("AddToCart.aspx");
}
I have use Add Wacth in Visual Studio, and i get this result
1.$exception {"Input string was not in a correct format."} System.FormatException
2.qdata = cell.Text This expression causes side effects and will not be evaluated
3.TableCell cell = GridView1.Rows[e.RowIndex].Cells[0]; error CS1073: Unexpected token 'cell'