BUTTON UI
Button 点击事件
protected void cb_Click(object sender, EventArgs e)
{
Button ibtn = (Button)sender;
GridViewRow gr = (GridViewRow)ibtn.Parent.Parent; //Row取值
}
Button 初始化
protected void GridViewName_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count; i++)//获取总列数
{
//如果是数据行则添加title
if (e.Row.RowType == DataControlRowType.DataRow)
{//设置title为gridview的head的text
e.Row.Cells[i].Attributes.Add("title", e.Row.Cells[i].Text.Trim());
e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;width:50px;overflow:hidden");
//此种写法能动态隐藏列,编辑时还能取到隐藏列的值
// if (i == XX)
//e.Row.Cells[i].Attributes.Add("style", "width:0px;visibility:hidden;")
//此种写法能动态隐藏列,编辑时还能取到隐藏列的值
Button Unblock = e.Row.FindControl("cb") as Button;
if (e.Row.Cells[12].Text.Trim() == "1")//根据特定列值修改此行按钮是否可用,如性别为男,禁止上女厕所
{
Unblock.Enabled = false;
}
else
{
Unblock.Enabled = true;
}
}
}
}