基于单元格值asp.net的更改的备用颜色gridview行 [英] alternate color gridview rows based on change of cell value asp.net

查看:84
本文介绍了基于单元格值asp.net的更改的备用颜色gridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1件商品

1件商品

2件商品

2件商品

3项

4项

4项

5项


我有一个gridview绑定到数据源。我想根据第一列的GROUPING更改行的颜色。我不知道列的值是什么,但基本上我需要在该列中的值发生更改时从一种颜色切换到另一种颜色。 (我用粗体显示了我的意思)再一次我不知道该栏中的值,所以我不能只说如果它等于1,那么做这个 - 我知道如何要做到这一点。 :))因此,只要第一列的值发生变化,就将行的颜色从蓝色切换到红色。 (例如上面的例子中的红色,红色,蓝色,蓝色,红色,蓝色,蓝色,红色)感谢您的任何建议。 (我是一个VB人,但可以设法翻译代码,如果需要的话,再次感谢)

(在C#中,但在这里它是在VB中)这工作。 :)我可以设置两个类的CSS并且工作正常。每当第1列中的项目发生更改时,它都会更改该行中的类。

  Dim currentClass As String =alternateDataRow
Dim currentGroup As String =

受保护的子gvPayrollRecords_RowDataBound(sender As Object,e As GridViewRowEventArgs)处理gvPayrollRecords.RowDataBound

如果e.Row.RowType = DataControlRowType。 DataRow Then

Dim rowGroup As String = e.Row.Cells(1).Text

如果rowGroup<> currentGroup Then
如果currentClass =datarow那么
currentClass =alternateDataRow
else
currentClass =datarow
End If

currentGroup = rowGroup
End If

e.Row.CssClass = currentClass

End If

End Sub
code>


1 item
1 item

2 item
2 item
3 item
4 item
4 item
5 item

I have a gridview bound to a datasource. I want to change the color of the rows based on the GROUPING of the first column. I do not know what the values of the column will be, but basically I need to switch from one color to the other color when the value in that column changes. (I used bold to show what I mean) Once again I don't know the value in that column, so I can't just say "if it equals 1 then do this" - I know how to do that. :)) So just switch the row color from blue to red each time the value in column one changes. (i.e. red, red, blue, blue, red, blue, blue, red per the example above) Thanks for any suggestions. (I'm a VB person, but can manage to translate code if need be. Thanks again)

解决方案

I found the following (cept in C#, but here it is in VB) This works. :) I can setup the css for the two classes and works out fine. Every time the item in column 1 changes it changes the class on the row.

Dim currentClass As String = "alternateDataRow"
Dim currentGroup As String = ""

Protected Sub gvPayrollRecords_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvPayrollRecords.RowDataBound

    If e.Row.RowType = DataControlRowType.DataRow Then

        Dim rowGroup As String = e.Row.Cells(1).Text

        If rowGroup <> currentGroup Then
            If currentClass = "datarow" Then
                currentClass = "alternateDataRow"
            Else
                currentClass = "datarow"
            End If

            currentGroup = rowGroup
        End If

        e.Row.CssClass = currentClass

    End If

End Sub

这篇关于基于单元格值asp.net的更改的备用颜色gridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆