locked
GridView Control, how to set different alignment styles for different columns? RRS feed

  • Question

  • User-790167105 posted

     Hi,

    If set the alignment style in the following, it applies to all columns.

    .AspNet-GridView table tbody tr td

    If I set in the control it self, it seemed it was ignored by css adapter.

    How can I set such as Col1 align to left, Col2 align to right, Col3 align to certer, ...?

    Thanks,

     

    Wednesday, August 5, 2009 3:35 AM

All replies

  • User236141260 posted

    You can do this on gridview rowdatabound event

    as


    e.Row.Cells[0].Style.Add("text-align", "center");

    Wednesday, August 5, 2009 4:56 AM
  • User-790167105 posted

     Hi,

    Thanks for your reply.

    Does it mean css-adapter cannot do this?

    If I do it as you indicated, the column header also is affected, but I don't want header be affected, how?

     

    Thank you very much.

    Wednesday, August 5, 2009 5:14 AM
  • User236141260 posted

    this code did not effact on header, it will change only your cell alignment. 

    Wednesday, August 5, 2009 7:09 AM
  • User-790167105 posted

     Hi, sorry, I mean the column heading, if really affected the column heading in my page.

    Thursday, August 6, 2009 2:39 AM
  • User-790167105 posted

     Hi,

    I have solved if by adding the following:

    if (e.Row.DataItemIndex>=0)  then do the alignment for the column.

    Thank you very much.

     

    Thursday, August 6, 2009 2:50 AM
  • User-1542018982 posted

    Hi,

    Have you try GridView Style properties?

    Right-click GridView -> Show Smart Tag (Open GridView Task window) -> Edit Column... -> Select your columns -> In the Properties window, scroll to Styles category, you can set ItemStyle, HeaderStyle, ControlStyle and Footer Style. (HorizontalAlign or CssClass)

    Hope it help

    Thursday, August 6, 2009 3:24 AM
  • User-790167105 posted

     Hi,

    I'm using CSS Friendly Control Adapter, I tried, the setting in properties are ignored.

    Anyway, I have solved the problem.

    Thank you very much.

    Thursday, August 6, 2009 5:18 AM