Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When i am updating in gridview radio button its not updating in database. here's my code:

C#
protected void rdbdiscontinued_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rd = (RadioButton)sender;
            GridViewRow row = (GridViewRow)rd.NamingContainer;
            Label lblprodid = (Label)row.FindControl("lblproductid");
            Label lbproductname = (Label)row.FindControl("lblproductname");
            Label lbcategoryid = (Label)row.FindControl("lblcategoryid");
            Label lbunit = (Label)row.FindControl("lblunitprice");
            Label txtunitstock = (Label)row.FindControl("lblunitsinstock");
            if (rd.Checked == true)
            {
                Productsbll pbl = new Productsbll();
                Products prod = new Products();
                row.Visible = false;
                prod.Productid = Convert.ToInt32(lblprodid.Text);
                prod.ProductName = lbproductname.Text;
                prod.CategoryID = Convert.ToInt32(lbcategoryid.Text);
                prod.UnitPrice = Convert.ToInt32(lbunit.Text);
                prod.UnitsinStock = Convert.ToInt32(txtunitstock.Text);
                pbl.UpdateProduct(prod);
            }
            GetProducts();
        }

in Updateproduct.cs

C#
public int UpdateProduct(Products prod)
        {
            con = new SqlConnection(cons);
            try
            {
                string query = "Update Products set ProductName=@productname, CategoryID=@categoryid, UnitPrice=@unitprice, UnitsInStock=@UnitsinStock, Discontinued=@Discontinued where ProductID=@productid";
                cmd = new SqlCommand(query, con);
                cmd.Parameters.AddWithValue("@productid", prod.Productid);
                cmd.Parameters.AddWithValue("@productname", prod.ProductName);
                cmd.Parameters.AddWithValue("@CategoryID", prod.CategoryID);
                cmd.Parameters.AddWithValue("@unitprice", prod.UnitPrice);
                cmd.Parameters.AddWithValue("@UnitsinStock", prod.UnitsinStock);
                cmd.Parameters.AddWithValue("@Discontinued", prod.Discontinued);
                con.Open();
                int i = cmd.ExecuteNonQuery();
                return i;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }


please help me where i did wrong and here when i click on radio button that row should be hide.

thank you.
Posted
Updated 13-Apr-12 21:51pm
v2
Comments
kishore sharma 14-Apr-12 3:56am    
Does your code goes inside if its checked
if (rd.Checked == true)
{
}

1 solution

In checkedchanged event you are not assigning Discontinued property value to True, but you are using it in UpdateProduct method.
So place this line
C#
prod.Discontinued=true;

before calling UpdateProduct method in Checked Changed Event


Hope this helps you.
 
Share this answer
 
v2
Comments
sreekanth12 14-Apr-12 4:06am    
thank you salini. its working.
P.Salini 14-Apr-12 4:22am    
You are Welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900