上的RowDataBound添加CSS类 [英] Adding CSS Class on RowDataBound

查看:178
本文介绍了上的RowDataBound添加CSS类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个CSS类追加到上的RowDataBound一行。我使用针对GridView中交替CSS类属性,因此我假设这是对的RowDataBound应用。如果编程指定一个CSS类的RowDataBound事件中则交替行样式的CSS类未应用该行的CssClass属性,即使你追加的CSS类

I'm trying to append a CSS class to a row on RowDataBound. I'm using the alternating css class property against the GridView, so I'm assuming this is applied on RowDataBound. If you assign a CSS class programatically to the CssClass property of the row within the RowDataBound event then the alternating row style css class is not applied, even if you append the CSS class.

下面是我得到了什么:

Protected Sub gvGeneral_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvGeneral.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
      If previousExpenseType <> e.Row.Cells(2).Text And previousExpenseType.Length > 0 Then
        e.Row.CssClass += "bottom-border"
      End If

      previousExpenseType = e.Row.Cells(2).Text
    End If
  End Sub

previousExpenseType 就是我正在做的比较反对的字符串。如果费用类型的变化,那么,我想有一个边界应用底部的&LT; TR方式&gt; 元素

previousExpenseType is just a String which I'm doing comparisons against. If the expense type changes, then I want to have a border applied to the bottom of the <tr> element.

任何想法如何解决这个问题?这似乎有后的RowDataBound一个事件的应用交替行样式CSS类行。

Any ideas how to get around this? It seems there's an event after RowDataBound that's applying the alternating row style css class to the row.

推荐答案

在你身边的另一个工作可能想尝试是使用后gridview的事件之一和循环的数据绑定的所有行后执行的检查和CSS类操作通过行自己。我知道,这将增加一些额外的处理时间,但具体取决于您正在显示的数据集的大小,它可能是值得的。

Another work around you may want to try is to perform your checks and CSS Class manipulation after all the rows are databound by using one of the later gridview events and looping through the rows yourself. I am aware that this would add some extra processing time, but depending on the size of the datasets your are displaying, it could be worth it.

这篇关于上的RowDataBound添加CSS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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