RowDataBound使用注意事项

来源:互联网 发布:游戏公司的程序员累吗 编辑:程序博客网 时间:2024/04/29 04:03

在RowDataBound方法使用时要注意先判断

例如:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {        if(e.Row.RowType==DataControlRowType.DataRow && this.GridView1.EditIndex!=e.Row.DataItemIndex)        {        if (e.Row.Cells[4].Text=="0")        {            e.Row.Cells[4].Text = "未审";        }        else        {            e.Row.Cells[4].Text = "已审";        }        }    }

原因是RowDataBound对每行都执行,但只是DataRow类型的数据行需要,头部和尾部类型的不需要. 此外当前编辑的行正在执行编辑命令,也不需要执行

原创粉丝点击