GridView 在编辑状态下动态控制每行的TextBox的宽度
protected void gvDexs_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) != 0)
{
for (int i = 2; i < e.Row.Cells.Count - 1; i++)
{
((TextBox)e.Row.Cells[i].Controls[0]).Width = Unit.Parse("30px");
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) != 0)
{
for (int i = 2; i < e.Row.Cells.Count - 1; i++)
{
((TextBox)e.Row.Cells[i].Controls[0]).Width = Unit.Parse("30px");
}
}
}
GridView的行状态是一个按位枚举值DataControlRowState,其下有Alternate,Edit,Insert,Normal 值,其中Alternate可与其他组合,如行的状态可能是Alternate|Edit。故判断一个行的状态不可单用“=”号判断,而因用位逻辑 的&判断,如判断行状态是否是Edit则应用如下表达式:
(e.Row.RowState & DataControlRowState.Edit) != 0
而不应用:
e.Row.RowState = DataControlRowStade.Edit