GridView RowStyle dependent on a property of the item the row is bound to

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    GridView RowStyle dependent on a property of the item the row is bound to

    I'm currently using a GridView and I want to set the CssClass for the Row depending on a property of the object that the row is being bound to.

    I tried the following:
    Code:
    <asp:GridView id="searchResultsGrid" runat="server" AllowPaging="true" PageSize="20" AutoGenerateColumns="false">
    
    <!-- The following line doesn't work because apparently "Code blocks 
    aren't allowed in this context -->
    [b]  <RowStyle CssClass="<%#IIF(DataBinder.Eval(Container.DataItem,"NeedsAttention","red","") %>[/b]
    
      <Columns>
    <!--............-->
      </Columns>
    </asp:GridView>
    Now I could simply handle theGridView's RowDataBound event and change the css class of the row there...but I'm trying to keep a clear separation between the UI and the page/business logic layers.


    I have no idea how to accomplish this and I'm looking forward to hearing any suggestions.

    Thanks,

    -Frinny
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I have discovered that this is impossible.

    I cannot do this in declarative markup.

    Nearly all of GridView's declarative properties (including GridView.RowSty le) are grid-level settings rather than row-level. Apart from TemplateFields , they are not bound data containers, so they don't have access to the data in their rows.

    This means that I have to do this in my .NET code during the the OnRowBound event.

    Disappointed,

    -Frinny

    Comment

    Working...