Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have write the below code to update to update data of gridview row... int ID = int.Parse((sender as LinkButton).CommandArgument);here ID is the datakey name..when i click the link button to update 2 row of gridview..then ID which is datakey name of 2nd row comes correct...but the problem is that by doing this it update string id,name and attendance of first row. datakey name value is of 2nd row...by doing this it update data of first row instead of second....
any solution or sugesstion???????
C#
string Id = row.Cells[0].Text;
                string name = row.Cells[1].Text;
                CheckBox attendance = row.FindControl("status") as CheckBox;








C#
protected void Update(object sender, EventArgs e) 
    {
        int ID = int.Parse((sender as LinkButton).CommandArgument);



        foreach (GridViewRow row in GridView2.Rows)
        {
            
            
            if (row.RowType == DataControlRowType.DataRow)
            {
               
               
                string Id = row.Cells[0].Text;
                string name = row.Cells[1].Text;
                CheckBox attendance = row.FindControl("status") as CheckBox;

                if (attendance.Checked)
                {

                    IITBAL.Attendance.UpdateAttendance(ID,Semester.Text.ToString(), Course_Name.Text.ToString(), SessionId.ToString(), Id.ToString(), name.ToString(), date.Text.ToString(), 1);
                    return;
                }
                else
                {
                    IITBAL.Attendance.UpdateAttendance(ID,Semester.Text.ToString(), Course_Name.Text.ToString(), SessionId.ToString(), Id.ToString(), name.ToString(), date.Text.ToString(), 0);
                    return;
                }

              
            }

         
        }
        Response.Redirect("Faculty Manage Attendance.aspx");
       
       
    }
Posted
Comments
ZurdoDev 24-Oct-14 10:08am    
I cannot understand what you are saying.

1 solution

C#
int ID = int.Parse((sender as LinkButton).CommandArgument);


Here you are getting the ID of the row, from where button is clicked. Then you are looping through all the rows and using this ID. That is wrong. That means for every row, the ID will be the same.

Inside the loop, you should get the ID. But ideally, I think, you should only update the row, from where button is clicked. Why you are updating all the rows? This is not logical.
 
Share this answer
 

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