Hi. I'm working on shopping cart kind of application, in this I will be entering ProdID,Price,Quantity,Amount etc in to my Texboxes
after clicking on the Next button the list has to be added into gridview row for each product id.
now my problem is after entering 2 or 3 products it will reach certain amount limit(as customer may only have 500Rs).
so i may need to remove certain row to reduce the amount.
here to notice that after submit(not Next button)only data will get in to database.
so im trying to remove particular row from gridview list items in which event i should handle this(auto generate delte or rowcommand ..)
how to remove from gridview list.
private void BindGrid(int rowcount)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("productId", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("productName", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("Price", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("Quantity", typeof(int)));
dt.Columns.Add(new System.Data.DataColumn("Amount", typeof(String)));
if (ViewState["CurrentRow"] != null)
{
for (int i = 0; i < rowcount + 1; i++)
{
dt = (DataTable)ViewState["CurrentRow"];
if (dt.Rows.Count > 0)
{
dr = dt.NewRow();
dr[0] = dt.Rows[0][0].ToString();
}
}
dr = dt.NewRow();
dr[0] = TxtProductId.Text.ToString();
dr[1] = TxtProductName.Text.ToString();
dr[2] = decimal.Parse(Txtprice.Text.ToString());
dr[3] = txtQuantity.Text.ToString();
dr[4] = int.Parse(txtQuantity.Text.ToString()) * decimal.Parse(Txtprice.Text.ToString());
dt.Rows.Add(dr);
}
-----------
private void BindGrid(int rowcount)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("productId", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("productName", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("Price", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("Quantity", typeof(int)));
dt.Columns.Add(new System.Data.DataColumn("Amount", typeof(String)));
if (ViewState["CurrentRow"] != null)
{
for (int i = 0; i < rowcount + 1; i++)
{
dt = (DataTable)ViewState["CurrentRow"];
if (dt.Rows.Count > 0)
{
dr = dt.NewRow();
dr[0] = dt.Rows[0][0].ToString();
}
}
dr = dt.NewRow();
dr[0] = TxtProductId.Text.ToString();
dr[1] = TxtProductName.Text.ToString();
dr[2] = decimal.Parse(Txtprice.Text.ToString());
dr[3] = txtQuantity.Text.ToString();
dr[4] = int.Parse(txtQuantity.Text.ToString()) * decimal.Parse(Txtprice.Text.ToString());
dt.Rows.Add(dr);
}
protected void Grd_sales_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}