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

Changing Item CssClass

2 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tony
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" 
        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 Answers, 1 is accepted

Sort by
0
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.

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.
0
Brad
Top achievements
Rank 1
answered on 30 Mar 2020, 11:17 AM

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

Tags
Grid
Asked by
Tony
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Brad
Top achievements
Rank 1
Share this question
or