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

Changing Item CssClass

2 Answers 244 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Tony asked on 24 Jan 2011, 07:19 PM
I am using a Telerik RadGrid with ASP.Net 4.0 and Visual Studio 2010.

I am trying to tweak the CssClass for an ItemStyle based on a database field that has a status code.  I want to use R_STATUS_X to set the item to use the CSS style "status_N" where N is the value in R_STATUS_X .  I tried "<ItemStyle CssClass='Status_<%# DataBinder.Eval("R_STATUS_1") %>'></ItemStyle>" but it did not evaluate "R_STATUS_1" and instead replaced it with
<td class=".Status_&lt;%# DataBinder.Eval(&quot;R_STATUS_X&quot;) %>" align="right" style="white-space:nowrap;">

Hmm, It looks like if I edit the ASPX page while debugging, this works, but if I recompile, it does not.  Is there something that the component is doing at compile time to stop this and if so, is there a way to force it to work?

I am trying:
    <telerik:RadGrid ID="RadGrid2" runat="server" width="99%" AllowPaging="True"
        AllowSorting="True" GridLines="None" ShowStatusBar="True"
        AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound" 
        AllowCustomPaging="True" EnableLinqExpressions="False" Skin="WebBlue" 
        <ClientSettings AllowColumnsReorder="True">
            <Scrolling AllowScroll="True" UseStaticHeaders="False" />
            <CommandItemSettings ExportToPdfText="Export to Pdf" ShowExportToPdfButton="True">
            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                <telerik:GridBoundColumn DataField="R_VAL_1" HeaderText="R_VAL_1" EmptyDataText="-" >
                    <HeaderStyle CssClass="headerstyle"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Right" Wrap="False" BorderWidth="5px" 
                    CssClass='SomeGeneralCss Status_<%# DataBinder.Eval("R_STATUS_1") %>'></ItemStyle>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" />
        <FilterMenu EnableImageSprites="False">
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">

2 Answers, 1 is accepted

Sort by
Iana Tsolova
Telerik team
answered on 27 Jan 2011, 11:42 AM
Hello Mark,

I cannot find a reason for the code to work in debug and not in release mode.
However, you can try setting the item CssClass in the ItemDataBound event of the grid or in the grid PreRender event by looping throught the items and see if this works for you.

the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Top achievements
Rank 1
answered on 30 Mar 2020, 11:17 AM

So others that find this thread will know the answer, see aforementioned stackoverflow link.

"My understanding is that using server tags for attributes requires that the server tag be used for the entire attribute value. Try changing it to this:

style='<%# "color:#6D7B8D;font-size:" + DataBinder.Eval(Container.DataItem, "Title") + ";" %>'

Notice how the entire style attribute is being constructed in C# code between the server tags."

Asked by
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Top achievements
Rank 1
Share this question