天天看点

在FooterTemplate内显示DropDownList控件

如果想在Gridview控件FooterTemplate内显示DropDownList控件供用户添加数据时所应用。有两种方法可以实现,一种是在GridView控件的OnRowDataBound事件中写程序,另外一种是在GridView控件OnDataBinding事件中实现。

首先写GridView控件,并定制好FooterTemplate:

​​

在FooterTemplate内显示DropDownList控件

在cs中写,绑定数据给GridView控件:

在FooterTemplate内显示DropDownList控件

此时浏览网页效果是这样子:

在FooterTemplate内显示DropDownList控件

OK,现在我们先在OnRowDataBound事件中来实现:

在FooterTemplate内显示DropDownList控件

去cs写此事件:

在FooterTemplate内显示DropDownList控件

上图中一个实例类:

这个类,可以参考这个链接

现在运行网页浏览一下看看:

在FooterTemplate内显示DropDownList控件

现在,我们尝试另外一种方法,就是在GridView控件的OnDataBinding事件实现,先来看看Html markup:

在FooterTemplate内显示DropDownList控件

在cs中OnDataBounding事件:

在FooterTemplate内显示DropDownList控件

两种方法,浏览效果均一样。

继续阅读