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


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

在FooterTemplate内显示DropDownList控件_FindControl


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

在FooterTemplate内显示DropDownList控件_OnRowDataBound_02



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

在FooterTemplate内显示DropDownList控件_FooterRow_03



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

在FooterTemplate内显示DropDownList控件_OnRowDataBound_04



去cs写此事件:

在FooterTemplate内显示DropDownList控件_GridView_05




上图中一个实例类:



InsusListControlUtility objInsusListControlUtility = new InsusListControlUtility();


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

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

在FooterTemplate内显示DropDownList控件_OnRowDataBound_06

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

在FooterTemplate内显示DropDownList控件_FindControl_07



在cs中OnDataBounding事件:

在FooterTemplate内显示DropDownList控件_FindControl_08


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