Updations In Datagrid

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Updations In Datagrid as PDF for free.

More details

  • Words: 543
  • Pages: 6
Grid item value to be replaced means Or Datalist item value After databind Foreach(Datagriditem or Datalistitem li in datagriedid or datalistid) { Label lb=(label)li.findcontrol(“label id”); lb.text=lb.text.replace(“***”,”’”); }

protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e) { string strdel = ((Label)e.Item.FindControl("lblproduct")).Text; con.Open(); SqlCommand cmddel = new SqlCommand("delete from addcart where productid='" + strdel + "'", con); cmddel.ExecuteNonQuery(); con.Close(); fill(); } protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e) { fill(); DataGrid1.EditItemIndex = -1; DataGrid1.DataBind(); } protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e) { fill(); DataGrid1.EditItemIndex = e.Item.ItemIndex; DataGrid1.DataBind(); } protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e) { try { con.Open(); string proid = ((Label)e.Item.FindControl("lblproduct")).Text; string productname = ((Label)e.Item.FindControl("lbproductname")).Text; int quantity = Convert.ToInt32(((TextBox)e.Item.FindControl("txtquantity")).Text); float price = float.Parse(((Label)e.Item.FindControl("lbunitprice")).Text); SqlCommand cd = new SqlCommand("select quantity from product where productid='" + proid + "'", con); SqlDataReader dq = cd.ExecuteReader();

dq.Read(); int cnt = Convert.ToInt32(dq["quantity"].ToString()); dq.Close(); if (quantity > cnt) { Label1.Visible = true; Label1.Text = "Available Quantity is:"+cnt; } else { Label1.Visible = false; float subprice = quantity * price; string queryup1 = "update addcart set quantity='" + quantity.ToString() + "',price='" + subprice.ToString() + "' where productid='" + proid.ToString() + "' and orderid='" + Session["genid"].ToString() + "'"; SqlCommand cmd1 = new SqlCommand(queryup1, con); cmd1.ExecuteNonQuery(); con.Close(); DataGrid1.EditItemIndex = -1; fill(); }

}

protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e) { string strdel = ((Label)e.Item.FindControl("lblproduct")).Text; con.Open(); SqlCommand cmddel = new SqlCommand("delete from addcart where productid='" + strdel + "'", con); cmddel.ExecuteNonQuery(); con.Close(); fill(); } protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e) { fill(); DataGrid1.EditItemIndex = -1; DataGrid1.DataBind(); } protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e) { fill(); DataGrid1.EditItemIndex = e.Item.ItemIndex; DataGrid1.DataBind(); } protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e) { try { con.Open(); string proid = ((Label)e.Item.FindControl("lblproduct")).Text; string productname = ((Label)e.Item.FindControl("lbproductname")).Text;

int quantity = Convert.ToInt32(((TextBox)e.Item.FindControl("txtquantity")).Text); float price = float.Parse(((Label)e.Item.FindControl("lbunitprice")).Text); SqlCommand cd = new SqlCommand("select quantity from product where productid='" + proid + "'", con); SqlDataReader dq = cd.ExecuteReader(); dq.Read(); int cnt = Convert.ToInt32(dq["quantity"].ToString()); dq.Close(); if (quantity > cnt) { Label1.Visible = true; Label1.Text = "Available Quantity is:"+cnt; } else { Label1.Visible = false; float subprice = quantity * price; string queryup1 = "update addcart set quantity='" + quantity.ToString() + "',price='" + subprice.ToString() + "' where productid='" + proid.ToString() + "' and orderid='" + Session["genid"].ToString() + "'"; SqlCommand cmd1 = new SqlCommand(queryup1, con); cmd1.ExecuteNonQuery(); con.Close(); DataGrid1.EditItemIndex = -1; fill();

} }




<small>





>


<EditItemTemplate>



>





>





Related Documents

Updations In Datagrid
November 2019 5
Datagrid
April 2020 13
Datagrid
November 2019 14
Paging In Datagrid
November 2019 11
How Paging In Datagrid
November 2019 8