Gridview insert,update,delete records

Posted by Sathiya_Narayanan under ASP.NET on 7/2/2012 | Points: 10 | Views : 2476 | Status : [Member] | Replies : 6
Hi,

In a grid view performing insert, update, delete operation.
Here when we click the edit button in the selected row is converts into textboxes after updating the data wen we click should the update button it
shows error as " Object reference not set to an instance of an object." whats this error..









Thanks,

SATHIYANARAYANAN


Responses

Posted by: CGN007 on: 7/2/2012 [Member] Silver | Points: 25

Up
0
Down
Please give more details about the error?Also what you have already done?

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

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

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

Posted by: Muralidosscm on: 7/3/2012 [Member] Starter | Points: 25

Up
0
Down
http://www.codeproject.com/Articles/24085/Insert-Update-Delete-with-Gridview-simple-way


Regards
Muralidoss M

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

Posted by: Premalatha on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

You just go this link,
If it solve your problem Mark as Answer Please
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html

Premalatha
Software Engineer

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

Posted by: Rimi1289 on: 5/14/2013 [Member] Starter | Points: 25

Up
0
Down
Suggesting.

This article is well written with demos both in C# and Vb.Net. Its definitely worth reading at least once.

http://www.encodedna.com/2013/05/add-new-row-using-gridview.htm

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

Posted by: perfectchourasia-9163 on: 5/28/2013 [Member] Starter | Points: 25

Up
0
Down
http://www.aspnetcodes.com/2011/09/editable-gridview.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

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

Login to post response