TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ashwini patel
NA
143
9.7k
Gridview editing
Sep 10 2018 11:00 PM
I have a gridview. While editing the gridview, I have textbox as well as dropdownlist. On editing the textbox value and updating the gridview, the dropdownlist value is getting changed. It is taking the first value from the list item. The selected value is getting changed each time on changing other items. How can i resolve this issue.
CODE
protected void gvImage_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int imageId = Convert.ToInt32(gvImage.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)gvImage.Rows[e.RowIndex];
TextBox employeecode = (TextBox)gvImage.Rows[e.RowIndex].FindControl("Employeecode");
TextBox employeename = (TextBox)gvImage.Rows[e.RowIndex].FindControl("Employeename");
string Contract = (gvImage.Rows[e.RowIndex].FindControl("DropDownList1") as DropDownList).SelectedItem.Value;
TextBox Skill = (TextBox)gvImage.Rows[e.RowIndex].FindControl("Skill");
FileUpload FileUpload1 = (FileUpload)gvImage.Rows[e.RowIndex].FindControl("FileUpload1");
string path = "~/Images/";
if (FileUpload1.HasFile)
{
path += FileUpload1.FileName;
FileUpload1.SaveAs(MapPath(path));
}
else
{
Image img = (Image)gvImage.Rows[e.RowIndex].FindControl("Image");
path = img.ImageUrl;
}
gvImage.EditIndex = -1;
con = new SqlConnection(connStr);
con.Open();
SqlCommand cmd = new SqlCommand("update Listofemployee set Employeecode='" + employeecode.Text + "',Employeename='" + employeename.Text + "',Contract='" + Contract + "', Skill='" + Skill.Text + "',Image='" + path + "' where ImageId='" + imageId + "'", con);
cmd.ExecuteNonQuery();
con.Close();
ImageData();
}
Reply
Answers (
1
)
Server Error in Application
How to implement paging concept in ASP.Net MVC?