如何禁用网格视图的行

时间:2010-12-29 11:41:13

标签: asp.net

ghyath我只在rowdatabound控件中做,但事情就是每当我禁用第1页的第3行时它会自动禁用我想要的第3,第3,第4 ......页面的第3行

2 个答案:

答案 0 :(得分:1)

您可以使用PageIndexRowIndex属性:

protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    var grid = (GridView) sender;
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Enabled = (grid.PageIndex != 0 || e.Row.RowIndex != 2);
    }
}

如果要禁用单击按钮的行,请使用以下方法:

protected void BtnDisableRow_Click(object sender, EventArgs e)
{
    GridViewRow row = (GridViewRow)((Button) sender).NamingContainer;
    row.Enabled = false;
}

答案 1 :(得分:0)

使用RowDataBound事件>>

protected void gvLeaveDetail_RowDataBound(object sender,GridViewRowEventArgs e)         {             if(e.Row.RowType == DataControlRowType.DataRow)             {                 string status = Convert.ToString(DataBinder.Eval(e.Row.DataItem,“3rdROW”));

            if(status== "accept")
            {
              // Cells[7] : 3rd Row then it should be '4' then it will work on only that row 
                e.Row.Cells[7].ForeColor = System.Drawing.Color.Green;
            }
            else if (status == "reject")
            {
                e.Row.Cells[7].ForeColor = System.Drawing.Color.Red;
            }
        }
    }
相关问题