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

Conditional Row Formatting

0 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Susan
Top achievements
Rank 1
Susan asked on 07 Sep 2011, 10:36 PM
UPDATE: D'Oh - seems to always be the simplest things that get overlooked. Need to have the  OnItemDataBound="RadGrid4_ItemDataBound" in the RadGrid definition. Now to get the formatting right...

Hi. I'm trying to apply some conditional formatting to a row in a RadGrid. I'm trying to get the values in a row formatted one way or another based on a column in each row. For the RadGrid itself in the .aspx I have in part:

<telerik:RadGrid ID="RadGrid4" runat="server" DataSourceID="SqlDataSource4"
                       GridLines="None" AllowSorting="True" AllowPaging="True">
        <ClientSettings>
          <Selecting AllowRowSelect="True" />
        </ClientSettings>
        <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource4">
          <RowIndicatorColumn>
            <HeaderStyle Width="20px" />
          </RowIndicatorColumn>
          <ExpandCollapseColumn>
            <HeaderStyle Width="20px" />
          </ExpandCollapseColumn>
          <Columns>
            <telerik:GridBoundColumn DataField="MetricName" HeaderText="" ReadOnly="True"
                                     UniqueName="MetricName" HeaderTooltip="Metric Name">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="MetricValue" DataType="System.Decimal"
                                     HeaderText="Sales" ReadOnly="True" DataFormatString="{0:$###,###.##}"
                                     UniqueName="MetricValue" HeaderTooltip="Metric Value">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="MetricComp" DataType="System.Decimal" DataFormatString="{0:#.#%;(#.#%);''}"
                                     HeaderText="Comp %" ReadOnly="True" HeaderTooltip="MetricComp"
                                     UniqueName="MetricComp">
            </telerik:GridBoundColumn>
 
          </Columns>
        </MasterTableView>
      </telerik:RadGrid>

In the code behind .cs page I have:

protected void RadGrid4_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {    
        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            if (dataItem["MetricName"].Text == "Average Trans")
                dataItem.CssClass = "AverageTransRowClass";
        }
    }

From testing, it appears the ItemDataBound is never getting fired. Any ideas on what I can do to debug this? Thanks!

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Susan
Top achievements
Rank 1
Share this question
or