简体   繁体   English

从文件后面的代码在GridView ASP.NET的标题列中添加/删除类

[英]Add/Remove Class in header column in GridView ASP.NET from code behind file

I have a GridView with accessible headers that can choose options from drop down. 我有一个带有可访问标题的GridView,可以从下拉菜单中选择选项。 I have a function in jquery to avoid sorting on applying noSort class on header. 我在jquery中有一个函数,以避免在对标头应用noSort类时进行排序。 I basically want that if Count of rows in GridView is greater than 500, it should add class noSort on GridView headers on drop down selected index change and if less than that then it should remove noSort from header 我基本上希望,如果GridView中的行数大于500,则应在下拉选定的索引更改时在GridView标头上添加类noSort,如果小于该类,则应从标头中删除noSort

You can make use of gridviews "Header Style" property..:) 您可以使用gridviews的“标题样式”属性。.:)

Once after loading the data into the grid, make sure, you run the following snippet like:(Assuem id of the gridview as gvSagar): 将数据加载到网格后,请确保运行以下代码段:(gridview的assuem id为gvSagar):

gvSagar.HeaderStyle.CssClass="requiredClassName"; gvSagar.HeaderStyle.CssClass =“ requiredClassName”;

I found the answer, call below function on Databound event of gridview that will be called each time gridview data changes so the header columns can be individually broken down: 我找到了答案,在gridview的Databound事件上调用下面的函数,每次gridview数据更改时都会调用此函数,因此可以分别分解标题列:

if (gvName.Rows.Count > sortingLimit)  //Check for rowcount for limit before sorting
        {
            gvName.HeaderRow.Cells[0].CssClass = "noSort fieldAlignCenter";
            gvName.HeaderRow.Cells[1].CssClass = "noSort";
            gvName.HeaderRow.Cells[2].CssClass = "noSort";
            gvName.HeaderRow.Cells[3].CssClass = "noSort";
            gvName.HeaderRow.Cells[4].CssClass = "noSort";
            gvName.HeaderRow.Cells[5].CssClass = "noSort";
            gvName.HeaderRow.Cells[7].CssClass = "noSort";
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM