views:

895

answers:

2

i need your help give css property into gridview in the header of columns' Css. Up or Down image?

string AscCSS = "sortascheader";
        string DescCSS = "sortdescheader";

        foreach (DataControlField field in gvProducts.Columns)
      {
          for (int i = 0; i < gvProducts.Columns.Count; i++)
          {
              if (field.SortExpression == gvProducts.Columns[i].SortExpression)
              {
                  if (gvProducts.SortDirection == SortDirection.Ascending)
                      field.HeaderStyle.CssClass = DescCSS;
                  else
                      field.HeaderStyle.CssClass = AscCSS;
              }
          }
      }

i have this property in gridview generated("GridView Row DataBound EVENT"). Sorting is ok but Css propert not working. Such as. Up not converting to down icon?????

A: 

Add:

 field.HeaderStyle.CssClass.Remove();

above the if. Hopefully that helps

And also, why do you have 2 loops? Is there a need for the inner for statement

or

Through non-CSS approach:

myArrow.ImageUrl = "~/img_" + (GridView1.SortDirection == SortDirection.Ascending ? "asc" : "desc") + ".png";

or use CssClass on LinkButton (similar to how u use on headerstyle)

Otherwise, post your css please.

waqasahmed
A: 

I have some code to show how to do this here, but it not CSS either (but could be.)

You have it in the "Row DataBound EVENT" - in that post I also talk about the perfomance between this verses having it in the DataBound event.

JBrooks