Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 覆盖ASP.NET gridview控件的标题输出_C#_Asp.net_Gridview_Header - Fatal编程技术网

C# 覆盖ASP.NET gridview控件的标题输出

C# 覆盖ASP.NET gridview控件的标题输出,c#,asp.net,gridview,header,C#,Asp.net,Gridview,Header,是否有有效的方法覆盖ASP.NETGridView控件的页眉和页脚的HTML输出 我想实现一种类似于ASP.NETRepeater中的HeaderTemplate标记的方法,或者不需要在页面代码隐藏中包含动态构建HTML输出。如果这两种类型的选项可用ASP.NET GRIDVIEW控件。 ,您可能需要考虑使用AN。我已经将它们用于非常基本的事情,但正如注释所示: 控制适配器允许您 插入任何ASP.NET服务器控件 以及覆盖、修改和/或调整 渲染该对象的输出逻辑 控制 还包含几个“开箱即用”适配

是否有有效的方法覆盖ASP.NET
GridView
控件的页眉和页脚的HTML输出


我想实现一种类似于ASP.NET
Repeater
中的
HeaderTemplate
标记的方法,或者不需要在页面代码隐藏中包含动态构建HTML输出。如果这两种类型的选项可用ASP.NET <代码> GRIDVIEW控件。

,您可能需要考虑使用AN。我已经将它们用于非常基本的事情,但正如注释所示:

控制适配器允许您 插入任何ASP.NET服务器控件 以及覆盖、修改和/或调整 渲染该对象的输出逻辑 控制


还包含几个“开箱即用”适配器,您可以从这些适配器中提取示例,包括GridView。再说一次,我不是100%肯定你能做你想做的事,但确实值得一试。如果只不过是让另一个ASP.Net技巧在你的腰带下运行。

你也可以继承该控件并覆盖渲染函数。我不得不这样做来修复ASP.NET单选按钮的一个缺点。基本思路如下,您可以根据需要对其进行修改:


在Gridview中,您可以使用RowCreated事件完全“销毁”并重新创建页眉和/或页脚。在此事件期间,请检查以查看:

if (e.Row.RowType = DataControlRowType.Header)
{
     // At this point you have access to e.Row.Cells
     // You can now empty the collection and recreate it.
     // If you create a singular cell in the collection
     // you can then make its ColumnSpan reach across
     // the length of the entire table. Then inside this 
     // cell you can add any set of controls you want.
     // I've used this method to combine column headers
     // and add specialty controls that simply wouldn't
     // working using the HeaderTemplate
}

因为这是在RowCreated上完成的,所以在RowDataBound期间,您可以访问这些控件,然后可以根据数据以任何方式操作它们。这对于在页脚中进行复杂的计算、根据排序调整页眉中的图像等非常方便。

通过对行进行逐单元格检查来更改创建的行是一种方法,例如,如果您想在列中添加一个下拉列表以允许进行筛选,您可以这样做

if (e.Row.RowType = DataControlRowType.Header)
{
    e.Row.Cells[0].Controls.Clear();

    var ddlFilter = new DropDownList();
    //add options etc

    e.Row.Cells[0].Controls.Add(ddlFilter);
}

如果您要转换为单个单元格并添加新控件,那么我只需设置
ShowHeader=false
,并将我的标记/控件放在gridview上方

谢谢您提供的信息。我将研究我的下一个项目。