[BUG] Setting CssClass in a GridView RowDataBound event is ignored

Last post 04-21-2007 10:11 PM by bdemarzo. 1 replies.

Sort Posts:

  • [BUG] Setting CssClass in a GridView RowDataBound event is ignored

    04-21-2007, 3:37 PM
    • Member
      14 point Member
    • diosloco
    • Member since 04-21-2007, 7:06 PM
    • Posts 6
    Sometimes it is necessary to change the CSS for a row depending on data. The following example is pulled from http://asp.net/learn/dataaccess/tutorial11cs.aspx?tabid=63
    protected void HighlightCheapProducts_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // Make sure we are working with a DataRow
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Get the ProductsRow object from the DataItem property...
            Northwind.ProductsRow product = (Northwind.ProductsRow)
                ((System.Data.DataRowView)e.Row.DataItem).Row;
            if (!product.IsUnitPriceNull() && product.UnitPrice < 10m)
            {
                e.Row.CssClass = "AffordablePriceEmphasis";
            }
        }
    }

    However, when the GridView is rendered with the adapter, "AffordablePriceEmphasis" is ignored completely. In the source code of GridViewAdapter.cs, in the method GetRowClass, the first line is

        string className = "";

    I simply replaced it with

        string className = row.CssClass;

     and now it works as expected. It would be nice to see this changed in the CodePlex source as well. Note that this does not overwrite anything, it simply adds a second class like

        <tr class="AffordablePriceEmphasis AspNet-GridView-Alternate">

    Cheers!

  • Re: [BUG] Setting CssClass in a GridView RowDataBound event is ignored

    04-21-2007, 10:11 PM
    • Member
      435 point Member
    • bdemarzo
    • Member since 07-02-2002, 4:05 AM
    • New York
    • Posts 168

    Could you post these details on the CodePlex Issue Tracker for the project? That way it'll constantly be in our faces to review and implement the proposed fix.

     Thanks!

Page 1 of 1 (2 items)