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

RadGrid breaks when setting background color

3 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Levi
Top achievements
Rank 1
Levi asked on 27 Jun 2013, 04:04 AM
I've had this same code for years and it has always worked. Now with the latest release it is broken.  I'm not using any new features or anything like that. When this code runs the cells shift and become huge. So basically the cells become 5 times as big (in height) and the columns shift over (leaving a broken appearance). This code is abbreviated of course and called from the grid_prerender event during a post back. The grid is in an update panel. Also I'm using IE10. It works in 2013.1.417.45. As soon as i switch to the new dlls, it breaks.


foreach (GridDataItem item in grid.Items)
          {
              //Get the instance of the right type
              GridDataItem row = item as GridDataItem;
              try
              {
                  
                  string sColName = String.Empty;
                  string sValue = String.Empty;
                  string sValueField = String.Empty;
 
                  foreach (GridColumn col in grid.MasterTableView.Columns)
                  {
                      sColName = col.UniqueName;
 
                      if (sColName.Contains("String") && grid.MasterTableView.GetColumnSafe(sColName.Replace("String", "")) != null)
                      {
                          // If String is present we will use the numeric field equivalent without "String" for calculations
                          sValueField = sColName.Replace("String", "");
                      }
                      else
                      {
                          sValueField = sColName;
                      }
 
                      sValue = row[sValueField].Text.Replace("$", "").Replace(",", "").Replace("%", "").Replace("M", "");
 
                   
 
                      if (sValue.IsNumeric())
                      {
                           
                               
                              row[sColName].BackColor = ColorTranslator.FromHtml("#fce9b3");
                           
                      }
 
                      // Get rid of the border
                      row[sColName].BorderColor = Color.Transparent;
 
 
                       
                  }
              }

Also here is my markup in case you're interested:
<asp:UpdatePanel ID="upnlGridOverview" runat="server" UpdateMode="Conditional">
       <ContentTemplate>           
           <telerik:RadGrid ID="gridOverview" runat="server" AllowPaging="True" AllowSorting="True"
               AllowCustomPaging="True" ShowGroupPanel="false" AutoGenerateColumns="false" PageSize="10"
               MasterTableView-AllowCustomPaging="true" Skin="swExcel2010" EnableEmbeddedSkins="false"
               EnableEmbeddedBaseStylesheet="false" ShowFooter="false" OnNeedDataSource="gridOverview_NeedDataSource">
               <MasterTableView TableLayout="Fixed" OverrideDataSourceControlSorting="true" Width="100%"
                   Visible="true">
                   <PagerTemplate>
                       <uc1:GridPagerTemplate ID="GridPagerTemplate2" runat="server" />
                   </PagerTemplate>
                   <PagerStyle AlwaysVisible="true" />
                   <NoRecordsTemplate>
                       <uc2:GridNoRecordsTemplate ID="GridNoRecordsTemplate1" runat="server" />
                   </NoRecordsTemplate>
                   <Columns>
                       <telerik:GridBoundColumn UniqueName="Date" SortExpression="GroupDate" HeaderText="Date"
                           DataField="DateString" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left"
                           FooterAggregateFormatString="Total Dates:  {0:#,0}" FooterStyle-HorizontalAlign="Right"
                           Aggregate="Count">
                           <HeaderStyle></HeaderStyle>
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn UniqueName="Visitors" DataFormatString="{0:#,0}" SortExpression="Visitors"
                           HeaderText="Visits" DataField="Visitors" HeaderStyle-HorizontalAlign="Right"
                           ItemStyle-HorizontalAlign="Right" FooterAggregateFormatString="Avg:  {0:#,0}"
                           FooterStyle-HorizontalAlign="Right" Aggregate="Avg">
                           <HeaderStyle></HeaderStyle>
                       </telerik:GridBoundColumn>
      
                   </Columns>
                   <SortExpressions>
                   </SortExpressions>
               </MasterTableView>
               <GroupingSettings GroupContinuesFormatString="" GroupContinuedFormatString="" />
           </telerik:RadGrid>
       </ContentTemplate>
   </asp:UpdatePanel>

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 02 Jul 2013, 06:49 AM
Hi Levi,

I have prepared a sample RadGrid web site using the provided code snippets to test the described behavior. Can you please run the attached application and verify that it works as expected on your side, too?

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Levi
Top achievements
Rank 1
answered on 05 Jul 2013, 10:21 PM
It appears that it's actually another piece of code breaking it:

            foreach (GridColumn col in grid.MasterTableView.RenderColumns)
            {
                if (!col.HeaderText.Contains("</span>") && col.HeaderText.Contains("<br"))  // prevent editing on follow-up requests
                    {  
// Do nothing. It still breaks
   }
            }

For some reason, if I don't rebind the grid before running this code the grid breaks. The second columns shifts to where the first is barely visible. It only does this in the new version of the dll. I tried to edit your project but it only happens when the grid is inside a dynamically loaded user control. So basically a post back occurs then this code is fired off.

I have seen many problems like this where simply looping through the grids control collection without executing any code whatsoever will cause viewstate to stop working. It is quite bizarre and only happens with the telerik controls. I have it working for now by adding the extra rebind. Thanks for the help. 
0
Eyup
Telerik team
answered on 10 Jul 2013, 09:49 AM
Hi Levi,

I am glad that you have managed to resolve the issue. However, we are not able to replicate the issue locally. To assist you further, please provide us the exact steps to reproduce the issue or open a support ticket to send us a very basic sample runnable web site demonstrating the erratic behavior. Thus, we will be able to further analyze the problem and provide a proper explanation.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Levi
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Levi
Top achievements
Rank 1
Share this question
or