VS2015 GridView.RowDataBound 事件

https://blog.csdn.net/luxuejuncarl/article/details/1479870

https://www.bbsmax.com/A/Ae5R9KQAJQ/

1、简介:
.NET Framework 类库 
GridView.RowDataBound 事件 

注意:此事件在 .NET Framework 2.0 版中是新增的。

在GridView控件中将数据行绑定到数据时发生。

命名空间:System.Web.UI.WebControls
程序集:System.Web(在 system.web.dll 中)

 2、操作:

添加事件:右击gridview,点属性,点事件。找到数据,双击RowDataBound为添加gridView_RowDataBound事件。

 example:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
        //判断当前行是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
//用FindControl方法找到模板中的Label控件
Label lb1= (Label)e.Row.FindControl("Label1");
//因为RowDataBound是发生在数据绑定之后,所以我们可以
//判断Label绑定的数据,如果是True,就更改其text属性为男
                if (lb1.Text== "True")
                      lb1.Text = "男";
                else
                      lb1.Text = "female";
        }

 }

3、详细介绍:
  RowType
RowType可以确定GridView中行的类型,RowType是枚举变量DataControlRowType中的一个值。RowType可以取值包括 DataRow、Footer、Header、EmptyDataRow、Pager、Separator。很多时候,  我们需要判断当前是否是数据行,通过如下代码来进行判断:
   if (e.Row.RowType == DataControlRowType.DataRow)
 
4、FindControl方法是根据ID在Control所在的命名容器中寻找相应控件。

 

 

 

posted @ 2022-08-05 16:29  yinghualeihenmei  阅读(86)  评论(0编辑  收藏  举报