protected void btncart_Click(object sender, EventArgs e) { if (con.State == ConnectionState.Closed) { con.Open(); } int Quantity = Convert.ToInt32(0); if (Quantity == 0) { Quantity = 1; } else { Quantity = Quantity + 1; } mas_id(); string pro_id = (((Label)DataList1.Controls[0].FindControl("pro_id")).Text).ToString(); string pro_name = (((Label)DataList1.Controls[0].FindControl("pro_name")).Text).ToString(); float Price = float.Parse(((Label)DataList1.Controls[0].FindControl("Price")).Text); string pro_img = ((Image)DataList1.Controls[0].FindControl("pro_img")).ImageUrl; //int quantity = Convert.ToInt32(((TextBox)DataList1.Controls[0].FindControl("txtquantity")).Text); string master_id = (((Label)DataList1.Controls[0].FindControl("master_id")).Text).ToString();//error comes here SqlCommand cmd = new SqlCommand("insert into addcart values('" + master_id + "','" + pro_id + "','" + pro_name + "','" + Quantity + "','" + Price + "','" + pro_img + "')", con); cmd.ExecuteNonQuery(); con.Close(); }
con
DataList1
DataList1.Controls[0]
DataList1.Controls[0].FindControl("pro_id")
FindControl
Label lbl = (Label)DataList1.Controls[0].FindControl("master_id")).Text).ToString(); string master_id = lbl.Text;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)