1

如何在用户定义的函数中找到对gridview的控制......这会抛出

DataSet ds = objSelectAll.Paging(PageSize, PageNumber, USERID, ROLEID);

if (Session["Username"].ToString() == "admin")
{ 
    foreach (GridViewRow row in UserRoleGridView.Rows)
    {
        ImageButton ImgEditbtn = (ImageButton)row.FindControl("EditButton");
        ImageButton ImgDelbtn = (ImageButton)row.FindControl("DeleteButton");

        DataSet dsusr = objSelectAll.UserBasedPaging(PageSize, PageNumber, USERID, ROLEID);
        UserRoleGridView.DataSource = dsusr.Tables[1];
        UserRoleGridView.DataBind();

        ...
4

2 回答 2

0

试试这个

foreach (GridViewRow row in UserRoleGridView.Rows)
                {
                    ImageButton ImgEditbtn = (ImageButton)row[row.RowIndex].FindControl("EditButton");
                    ImageButton ImgDelbtn = (ImageButton)row[row.RowIndex].FindControl("DeleteButton");
                DataSet dsusr = objSelectAll.UserBasedPaging(PageSize, PageNumber, USERID, ROLEID);
                UserRoleGridView.DataSource = dsusr.Tables[1];
                UserRoleGridView.DataBind();
    }
于 2013-05-13T06:26:48.877 回答
0

您需要检查当前行是数据行还是标题行。

用于检查您需要编写的行类型

 if(row.RowType == DataControlRowType.DataRow) {
// do what ever you want
}

现在你的代码看起来像

  foreach(GridViewRow row in GridView1.Rows) {
        if(row.RowType == DataControlRowType.DataRow) {
      // do what ever you want

    }
}

我希望它能解决你的问题。

于 2013-05-13T06:25:35.563 回答