Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
ASP.net Gridview operation using Entity Framework
Ashwanikumar singh
Jun 3 2016 6:53 AM
304
Reply
I am performing Crud operation in asp.net using Entity framework
Everything thing is working fine but when i am updating the rows, it showing me null reference exception .
protected void datagrid1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = datagrid1.Rows[e.RowIndex];
int customerId = (int)(datagrid1.DataKeys[e.RowIndex].Value);
string firstname = (row.FindControl("txtFirstName") as TextBox).Text
; //h
ere i am getting exception
, nullreference exception
string lastname = (row.FindControl("txtLastName") as TextBox).Text;
int age = Convert.ToInt32(row.FindControl("txtAge") as TextBox);
using (NORTHWNDEntities entities = new NORTHWNDEntities())
{
studentDetail customer = (from c in entities.studentDetails
where c.Id == customerId
select c).FirstOrDefault();
customer.FirstName =firstname;
customer.LastName= lastname;
customer.Age = age;
entities.SaveChanges();
}
datagrid1.EditIndex = -1;
GetStudent();
}
Any help or suggestion would be much appreciated
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
How to get the dropdownlist value?
I want to select records from database where condition.