(Gridview)Object reference not set to an instance of an object whats this error

Posted by Sathiya_Narayanan under ASP.NET on 7/2/2012 | Points: 10 | Views : 4183 | Status : [Member] | Replies : 3
Hi
This is my code for update when i click update button in grid view it shows this error "Object reference not set to an instance of an object whats this error"

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
int Id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
int intResult = 0;
TextBox Name = (TextBox)row.FindControl("txtname");
TextBox Phonenumber = (TextBox)row.FindControl("txtPhonenumber");
TextBox Emailaddress = (TextBox)row.FindControl("txtmailid");
TextBox Dob = (TextBox)row.FindControl("txtdob");
TextBox Address = (TextBox)row.FindControl("txtadd");
TextBox City = (TextBox)row.FindControl("txtcity");

clsBAL pBAL = new clsBAL();
try
{
intResult = pBAL.Updatecontact(Id,Name.Text,Phonenumber.Text,Emailaddress.Text,Dob.Text,Address.Text,City.Text);
if (intResult > 0)
lblMessage.Text = "Record is Updated";
else
lblMessage.Text = "Record cannot update";
}
catch (Exception ex)
{
lblMessage.Text = ex.Message.ToString();
}
finally
{
pBAL = null;
}
GridView1.EditIndex = -1;
BindGrid1();
}

SATHIYANARAYANAN


Responses

Posted by: Kamalakanta.Nayak09 on: 7/2/2012 [Member] Starter | Points: 25

Up
0
Down
intResult = pBAL.Updatecontact(Id,Name.Text.Trim(),Phonenumber.Text.Trim(),Emailaddress.Text.Trim(),Dob.Text,Address.Text.Trim(),City.Text.Trim());

Thanks,
K.K

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sathiya_Narayanan on: 7/2/2012 [Member] Starter | Points: 25

Up
0
Down
It shows the same error

"Object reference not set to an instance of an object whats this error"



SATHIYANARAYANAN

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

put the break point on GridView1_RowUpdating event and then see if any textbox is null or Not

I think it was not able to find element.Check each elements name in design page and in this event

all the best

Regards

R D Patel

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response