Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi folks,
I am doing update record from Gridview and but updation of record in not happens
C#
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
       {

           try
           {

               objBusinessUI.ProductCategory_ID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
               GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
               objBusinessUI.ProductCategory_Name = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("txtProdCategory"))).Text.Trim();
             //  objBusinessUI.ProductCategory_Name = (GridView1.Rows[e.RowIndex].FindControl("txtProdCategory") as TextBox).Text;
               objBusinessUI.UpdatedBy = "Admin";
               objBusinessUI.UpdatedOn = DateTime.Now;
               string strmsg = objDataUI.UpdateProductCat(objBusinessUI);
               if (strmsg == "SUCCESS")
               {

               }
               else
               {

               }
               GridView1.EditIndex = -1;
               BindGridData();
         }

this is my row updating event code..so please try to help me
thanxx in advance
Posted
Updated 26-Sep-13 23:29pm
v2
Comments
JoCodes 28-Sep-13 15:44pm    
are you getting any error?
indrajeet jadhav 30-Sep-13 0:40am    
Yes.i am getting errors ..its throws exception..textbox in grid view doesnt get any value.thats why it throws Null Reference Exception
JoCodes 30-Sep-13 5:23am    
That means your Textbox control inside the gridview was not able to find through the Findcontrol method ,so its null
JoCodes 30-Sep-13 5:35am    
Try a null check here ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("txtProdCategory")))

1 solution

check your grid view bind method on page load. is it inside if(!isPostBack) ???
 
Share this answer
 
Comments
indrajeet jadhav 30-Sep-13 0:41am    
Yes ..It has IsPostBack

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