如何在自定义函数中找到网格视图的控件...这抛出了
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();
...发布于 2013-05-13 14:25:36
需要检查当前行是数据行还是表头行。
为了检查你需要写的row类型
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-13 14:26:49
试试这个
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();
}https://stackoverflow.com/questions/16515870
复制相似问题