关于asp.net中gridview的问题 [英] Question about gridview in asp.net

查看:92
本文介绍了关于asp.net中gridview的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已编写以下代码进行更新以更新gridview行的数据... int ID = int.Parse((发件人为LinkBut​​ton).CommandArgument);这里的ID是数据键名称..当我点击链接按钮更新2行gridview..then ID是第2行的datakey名称正确...但问题是这样做,它更新字符串ID,名称和第一排的出席。 datakey名称值是第二行...通过这样做它更新第一行的数据而不是第二行....

任何解决方案或sugesstion ???????

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???????

string Id = row.Cells[0].Text;
                string name = row.Cells[1].Text;
                CheckBox attendance = row.FindControl("status") as CheckBox;









< br $> b $ b













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");
       
       
    }

推荐答案

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





这里是获取行的ID,从中点击按钮。然后循环遍历所有行并使用此ID。那是错的。这意味着对于每一行,ID都是相同的。



在循环中,你应该得到ID。但理想情况下,我认为,您应该只更新按钮所在的行。为什么要更新所有行?这不符合逻辑。



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.


这篇关于关于asp.net中gridview的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆