我需要在gridview 中启用或禁用按钮。基本上每一行都有这个按钮,点击这个按钮,它会重定向到具有相应行 ID 的其他页面。我需要为某些特定用户禁用按钮。我将从会话中获取用户名。
问问题
15911 次
3 回答
3
尝试这个:
protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
Button button = (Button)e.Row.FindControl("btnSubmit");
int Id = (int) ((DataRowView) e.Row.DataItem)["Id"];
if(Id == Convert.ToInt32(Session["Id"]))
{
button.Enabled = false;
}
else
{
button.Enabled = true;
}
}
于 2013-07-24T08:20:27.590 回答
1
您可以在RowDataBound事件中找到按钮并根据条件禁用它
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button buttonId= (Button )e.Row.FindControl("buttonId");
if(Session["Role"] == "admin")
buttonId.Enabled = false;
}
}
于 2013-07-24T08:20:15.757 回答
0
利用
protected void GridView1_DataBound(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (GridView1.Rows[i].Cells[1].Text == "NA")
{
Button btnVal= (Button)e.Row.FindControl("buttonSubmit");
btnVal.Enabled = false;
}
}
}
或者
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnVal= (Button )e.Row.FindControl("buttonSubmit");
if(Session["Role"] == "admin")
btnVal.Enabled = false;
}
}
于 2013-07-24T08:23:50.680 回答