【问题标题】:How to apply both cell color and alternating row color in aspx gridview at a time如何一次在 aspx gridview 中同时应用单元格颜色和交替行颜色
【发布时间】:2013-07-25 05:17:25
【问题描述】:

我正在使用 devexpress 的 aspxgridview。我在单元格上应用了不同的单元格样式颜色。现在我想将网格的备用行设置为阴影(相同颜色的光)。我正在应用交替颜色,但即使在设置 cellstyle-color 时也不会应用它。请任何人对此有任何想法。提前致谢。

【问题讨论】:

标签: c# asp.net css


【解决方案1】:

我建议你像这样使用 DevExpress css 样式(而不是设置 ASPxGridView 的属性):

.dxgvDataRow:hover
 {
   color: gray;
 }

您还可以使用 ASPxGridView 的 CssPostfix 属性为控件设置不同的样式。例如:

<dx:ASPxGridView ID="grid" runat="server"  Styles-CssPostfix="MyGrid" ...

将使用以下 css:

.dxgvDataRow_MyGrid:hover
 {
   color: gray;
 }

要观察 ASPx css 类名,只需在开发模式下打开浏览器并查看源代码,您可以找到这样的类:dxgvDataRowHover、dxgvFocusedRow、dxgvSelectedRow 和许多其他类。

这种样式自定义的优点是html标记不会为每个html元素创建样式属性,css编辑更容易更快,并且不需要通过设置属性来自定义每个ASPxGridView控件。

【讨论】:

    【解决方案2】:

    感谢 Anton,但我已经用 javascript 完成了。我正在使用如下表的偶数和奇数属性。这是我在 document.ready 函数中调用的函数。并从服务器端调用每个按钮的点击事件。

    函数颜色网格(){

            /*code for color coding grid*/
            $(".student_account td table tbody tr'[id]':odd").addClass('initial');
            $(".student_account td table tbody tr'[id]':even").addClass('initial');
    
            /* For odd Rows */
    
            // for first 3 columns
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(1)").css("background-color", "#EEEEEE");
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(2)").css("background-color", "#EEEEEE");
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(3)").css("background-color", "#EEEEEE");
    
            // for 4th and 5th column
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(4)").css("background-color", "#EBFAE3");
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(5)").css("background-color", "#EBFAE3");
    
    
            // for 6th t0 9th column
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(6)").css("background-color", "#F7F8D6");
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(7)").css("background-color", "#F7F8D6");
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(8)").css("background-color", "#F7F8D6");
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(9)").css("background-color", "#F7F8D6");
    
    
            // for 10th column
            $(".student_account td table tbody tr'[id]':odd  td:nth-child(10)").css("background-color", "#CBE6F7");
    
    
    
            /* For Even Rows */
    
            var name = "ctl00_ContentPlaceHolder1_grdScheduleStudent_DXHeadersRow";
    
            // for first 3 columns
            $(".student_account td table tbody tr'[id]':even  td:nth-child(1)").css("background-color", "#FFFFFF");
            $(".student_account td table tbody tr'[id]':even  td:nth-child(2)").css("background-color", "#FFFFFF");
            $(".student_account td table tbody tr'[id]':even  td:nth-child(3)").css("background-color", "#FFFFFF");
    
            // for 4th and 5th column
            $(".student_account td table tbody tr'[id]':even  td:nth-child(4)").css("background-color", "#F5FAF3");
            $(".student_account td table tbody tr'[id]':even  td:nth-child(5)").css("background-color", "#F5FAF3");
    
    
            // for 6th t0 9th column
            $(".student_account td table tbody tr'[id]':even  td:nth-child(6)").css("background-color", "#FBFCEA");
            $(".student_account td table tbody tr'[id]':even  td:nth-child(7)").css("background-color", "#FBFCEA");
            $(".student_account td table tbody tr'[id]':even  td:nth-child(8)").css("background-color", "#FBFCEA");
            $(".student_account td table tbody tr'[id]':even  td:nth-child(9)").css("background-color", "#FBFCEA");
    
    
            // for 10th column
            $(".student_account td table tbody tr'[id]':even  td:nth-child(10)").css("background-color", "#EDF8FE");
    
            $(".student_account td table tbody tr'[id=" + name + "]' td").css("background-color", "#56A52E");
    
            /*end color coding*/
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-05
      • 2022-12-25
      • 1970-01-01
      • 2020-11-29
      • 2016-07-08
      • 2013-11-18
      • 1970-01-01
      相关资源
      最近更新 更多