日期:2014-05-17 浏览次数:20518 次
在需要的时候,比如点编辑时增加一列
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BoundField field = new BoundField();
field.DataField = attribute.AttName;
field.HeaderText = attribute.AttName;
field.ItemStyle.CssClass = "gdv_pdmItemLeft";
field.HeaderStyle.CssClass = "gdv_pdmItemLeft";
//field.SortExpression = attribute.AttName;
GridView1.Columns.Add(field); //或者Insert
BindData();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState&DataControlRowState.Edit) == DataControlRowState.Edit && e.Row.RowType == DataControlRowType.DataRow)
{
var dataRow = e.Row.DataItem as DataRowView; //或者实体类
//取出要运算的列(或属性),得出时间差
//绑定至新增的列
}
}
在OnRowCancelingEdit和OnRowUpdated事件中移除相应的列