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>
>
>