微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

e.Item.Visible = False之后的DataGrid AlternatingItemStyle

如何解决e.Item.Visible = False之后的DataGrid AlternatingItemStyle

|| 我们有一个itemcommand使DataGridItem不可见。这打破了我们已经应用的交替配色方案。有没有一种方法可以重新应用样式而无需重新绑定或手动设置每个DataGridItem的BackColor属性?     

解决方法

        好的,这是一个完全的技巧,但是由于您似乎只关心BackColor,所以我可能会放弃所有项目样式,并创建具有两种颜色(一种在另一种之上)的正确颜色的图像。将其设置为水平拉伸并垂直重复作为网格本身的背景。由于您可以控制商品的高度,因此只需使用正确高度的线来创建图像即可。 我知道是完全骇客,但这100%的时间都可以奏效,并且很快就致力于渲染。     ,        没有任何东西可以自动修复不可见项上的AlternatingItemStyle,无论是DataGrid还是GridView(据我所知)。 因此,您可以手动修复它,例如,通过以下方式:
Private visibleRowIndex As Int32 = -1
Protected Sub GridView1_RowDataBound(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        hide/show the GridViewRow according to your business-logic\'
        If e.Row.Visible Then
            visibleRowIndex += 1
            e.Row.CssClass = If(visibleRowIndex Mod 2 = 0,\"GridRowStyle\",\"GridAlternatingRowStyle\")
        End If
    End If
End Sub
编辑:我已经忘记了您正在使用DataGrid:
Private visibleRowIndex As Int32 = -1
Protected Sub DataGridItem_ItemDataBound(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles GridView1.RowDataBound
    If e.Item.ItemType = ListItemType.Item OrElse _
         e.Item.ItemType = ListItemType.AlternatingItem Then
        \'show/hide the DataGridItem according to your business-logic\'
        If e.Item.Visible Then
            visibleRowIndex += 1
            e.Item.CssClass = If(visibleRowIndex Mod 2 = 0,\"GridAlternatingRowStyle\")
        End If
    End If
End Sub
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。