Changing Item CssClass

3 posts, 0 answers
  1. Tony
    Tony avatar
    4 posts
    Member since:
    Jan 2011

    Posted 24 Jan 2011 Link to this post

    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" 
            OnNeedDataSource="RadGrid2_NeedDataSource"
            AllowCustomPaging="True" EnableLinqExpressions="False" Skin="WebBlue" 
                HorizontalAlign="Center">
            <ClientSettings AllowColumnsReorder="True">
                <Scrolling AllowScroll="True" UseStaticHeaders="False" />
            </ClientSettings>
            <MasterTableView>
                <CommandItemSettings ExportToPdfText="Export to Pdf" ShowExportToPdfButton="True">
                </CommandItemSettings>
                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                </ExpandCollapseColumn>
                <Columns>
                    <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>
                    </telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                    </EditColumn>
                </EditFormSettings>
                <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" />
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
        </telerik:RadGrid>






  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 27 Jan 2011 Link to this post

    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.

    Greetings,
    Iana
    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.
  3. Brad
    Brad avatar
    2 posts
    Member since:
    Jul 2015

    Posted 30 Mar in reply to Tony Link to this post

    https://stackoverflow.com/a/3435649

    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."

Back to Top