This is a migrated thread and some comments may be shown as answers.

Dynamically Generated RadGrid and Alternating Rows

4 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mortman
Top achievements
Rank 1
mortman asked on 15 Nov 2013, 04:34 PM
I have a situation where I am generating a RadGrid control dynamically, and am seeing two issues:

1) The alternating rows are not working correctly - both rows and alternating rows have a white background; and
2) I am unable to change the background color programmatically.

I have a feeling #1 is interfering with #2, but can't figure out why. This is the code I use to generate the RadGrid:

                With rgStatusCenterMessages
 
                    .ID = Me.ID & "_RadGrid"
                    .AlternatingItemStyle.BackColor = Drawing.Color.LightGray
                    .Width = Unit.Percentage(99)
                    .AllowSorting = False
                    .AllowPaging = True
                    .PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
                    .AutoGenerateColumns = False
                    .GroupingEnabled = True
                    .ShowGroupPanel = False
                    .ShowStatusBar = False
 
                    With .ClientSettings
                        .AllowDragToGroup = False
                        .EnableAlternatingItems = True
                    End With
 
                    With .MasterTableView
                        .AlternatingItemStyle.BackColor = Drawing.Color.Aqua
                        .PageSize = 15
                        .ShowGroupFooter = False
                        .GroupsDefaultExpanded = True
                        .GroupLoadMode = GridGroupLoadMode.Client
 
                        Dim groupBy As GridGroupByExpression = GridGroupByExpression.Parse("AppName [Group] Group By AppName")
                        .GroupByExpressions.Add(groupBy)
 
                        .DataKeyNames = New String() {"FormNo"}
                    End With
 
                End With

You can see everything I've tried here, like enabling alternating items in the client settings, changing the back color of alternating items in the RadGrid (and in the MasterTableView as well), etc. But nothing seems to work. I've tried some rudimentary CSS changes, but haven't had luck with that either.

In the item data bound event I've tried using e.Item.BackColor, as well as assigning e.item to an object of type GridDataItem and then setting the back color of that object. Neither of these has worked, even though when debugging I see it changing the back color in the code. Like I said before, I wonder if #1 above is interfering with #2, but that's why I'm posting here. Any help is appreciated.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Nov 2013, 10:19 AM
Hi,

This is not an expected behavior. Below is a sample code snippet that i tried which works fine at my end. Please try it and let me know if any concern.

VB:
Private RadGrid1 As RadGrid
Protected Sub Page_Init(source As Object, e As System.EventArgs)
    RadGrid1 = New RadGrid()
    RadGrid1.MasterTableView.DataKeyNames = New String() {"OrderID"}
    RadGrid1.Skin = "Default"
    RadGrid1.Width = Unit.Percentage(100)
    RadGrid1.PageSize = 15
    RadGrid1.AllowPaging = True
    RadGrid1.AutoGenerateColumns = False
 
    RadGrid1.GroupingEnabled = True
    RadGrid1.MasterTableView.GroupsDefaultExpanded = True
    RadGrid1.MasterTableView.GroupLoadMode = GridGroupLoadMode.Client
    Dim groupBy As GridGroupByExpression = GridGroupByExpression.Parse("ShipCountry [Group] Group By ShipCountry")
    RadGrid1.MasterTableView.GroupByExpressions.Add(groupBy)
 
    RadGrid1.NeedDataSource += New GridNeedDataSourceEventHandler(AddressOf RadGrid1_NeedDataSource)
 
    'Add columns
    Dim boundColumn As GridBoundColumn
    boundColumn = New GridBoundColumn()
    boundColumn.DataField = "OrderID"
    boundColumn.HeaderText = "OrderID"
    RadGrid1.MasterTableView.Columns.Add(boundColumn)
    boundColumn = New GridBoundColumn()
    boundColumn.DataField = "ShipCountry"
    boundColumn.HeaderText = "ShipCountry"
    RadGrid1.MasterTableView.Columns.Add(boundColumn)
 
    'Add the RadGrid instance to the controls
    Me.PlaceHolder1.Controls.Add(RadGrid1)
End Sub
 
Private Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
    RadGrid1.DataSource = GetDataTable("SELECT * FROM Orders")
End Sub

Thanks,
Princy
0
mortman
Top achievements
Rank 1
answered on 05 Dec 2013, 10:05 PM
It looks like we have pretty much the same code. I added the Skin property as you had, but everything else looks the same. Could it be a skin or theme that is overwriting what I have? I would have thought that what I put in the code would overwrite any theme/skin info though. I've actually changed this further just to see if I could get any change, and this still results in every row being white:

 With rgInbox
 
                    .ID = Me.ID & "_rgInbox_RadGrid"
                    .AlternatingItemStyle.BackColor = Drawing.Color.LightGray
                    .ItemStyle.BackColor = Drawing.Color.Aquamarine
                    .Skin = "Default"
                    .Width = Unit.Percentage(99)
                    .AllowSorting = False
                    .AllowPaging = True
                    .PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
                    .AutoGenerateColumns = False
                    .GroupingEnabled = True
                    .ShowGroupPanel = False
                    .ShowStatusBar = False
 
                    With .ClientSettings
                        .AllowDragToGroup = False
                        .EnableAlternatingItems = True
                    End With
 
                    With .MasterTableView
                        .AlternatingItemStyle.BackColor = Drawing.Color.Aqua
                        .ItemStyle.BackColor = Drawing.Color.Black
                        .PageSize = 15
                        .ShowGroupFooter = False
                        .GroupsDefaultExpanded = True
                        .GroupLoadMode = GridGroupLoadMode.Client
 
                        Dim groupBy As GridGroupByExpression = GridGroupByExpression.Parse("AppName [Group] Group By AppName")
                        .GroupByExpressions.Add(groupBy)
 
                        .DataKeyNames = New String() {"FormNo"}
                    End With
 
                End With
0
Princy
Top achievements
Rank 2
answered on 06 Dec 2013, 04:09 AM
Hi,

I'm not able to replicate the issue at my side. Can you try setting the AlternatingItemStyle using CSS as shown below:

VB:
_with3.AlternatingItemStyle.CssClass = "altRow"

CSS:
<style type="text/css">
 .altRow
 {
  background-color: Green !important;
 }
</style>

Thanks,
Princy

0
mortman
Top achievements
Rank 1
answered on 09 Dec 2013, 07:21 PM
Just to wrap this up, it ended up being a stylesheet thing that another developer had done. They made all <td> cells have a white background, so even after I set the row color, that was overriding my color. As soon as I told it to change the COLUMN color, all was well.

Thanks very much for your time and energy on this question!!!
Tags
Grid
Asked by
mortman
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
mortman
Top achievements
Rank 1
Share this question
or