if (!IsPostBack)
{
Bind()
}
void Bind()
{
}
this my sample coding you need to change...
if (e.CommandName == "Update")
{
butadd.Visible = false;
butaddupdate.Visible = true;
Button btnUpdate = (Button)e.CommandSource;
GridViewRow row = (GridViewRow)btnUpdate.NamingContainer;
}
protected void butaddupdate_Click(object sender, EventArgs e)
{
butadd.Visible = true;
butaddupdate.Visible = false;
Pruchase.Columns[1].Visible = true;
Pruchase.Columns[6].Visible = true;
DataTable dt = new DataTable();
if (ViewState["produ"] != null)
{
dt = (DataTable)ViewState["produ"];
int rowindex = Convert.ToInt32(Session["rowname"].ToString());
if (dt.Rows.Count >= 1 && rowindex != -1)
{
dt.Rows[rowindex]["Prod_id"] = Litemid.Text;
dt.Rows[rowindex]["prd_name"] = txtitems.Text;
dt.Rows[rowindex]["Prod_qty"] = txtqty.Text;
dt.Rows[rowindex]["Prod_rate"] = txtrate.Text;
Pruchase.DataSource = dt;
Pruchase.DataBind();
}
}
Litemid.Text = "";
txtitems.Text = "";
txtqty.Text = "";
txtrate.Text = "";
txttotal.Text = "";
foreach (GridViewRow row in Pruchase.Rows)
{
decimal Rate = Convert.ToDecimal(row.Cells[3].Text);
decimal qty = Convert.ToDecimal(row.Cells[4].Text);
Decimal Total = Rate * qty;
row.Cells[5].Text = Convert.ToString(Math.Round(Total, 2));
Amount = Amount + Total;
Pruchase.FooterRow.Cells[5].Text = Convert.ToString(Math.Round(Amount, 2));
Lamt.Text = Pruchase.FooterRow.Cells[5].Text;
}
Pruchase.Columns[1].Visible = false;
Pruchase.Columns[6].Visible = false;
}