datagrid css

on a dynamically created datagrid, how do you add programatically css to the Main TR and TD of the datagrid

OMSmartGrid.HeaderStyle  ?
LVL 1
alain123Asked:
Who is Participating?
 
rlawleyConnect With a Mentor Commented:
MyDataGrid.HeaderStyle.CssClass does assign a CSS class to the TR in the header row.  If you need to be able to access the TD inside this then I suggest you use a css selector.  For example, if you have a css class called headerrow, you can assign this to the TR of the header line using:

MyDataGrid.HeaderStyle.CssClass = "headerrow";

Then in css you can just do

TR.headerrow {
  /* Styles to apply to the TR */
}

TR.headerrow TD {
  /* Styles to apply to the TD within the header TR */
}

If this is not what you want to do then I have misunderstood you.
0
 
alain123Author Commented:
i meant to the header of the datagrid
0
 
rlawleyCommented:
Yes, you use DataGrid.HeaderStyle.  You can assign it a CssClass using MyDataGrid.HeaderStyle.CssClass, or you can set things separately, e.g. MyDataGrid.HeaderStyle.BorderWidth
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
alain123Author Commented:
i'm really looking to assign css classes to the main TR and TD of the datagrid
0
 
alain123Author Commented:
thank you, that's a solution to the problem.. too bad it cannot be on the c# code
0
 
alain123Author Commented:


by any chance do you know how to set only the outside border?

Grid.BorderStyle = System.Web.UI.WebControls.BorderStyle.Outset;  i'm trying something like that but doesn't work..
0
 
rlawleyCommented:
You don't have to use CSS, but it's easier as it removes some of the formatting from the code.  You can still use MyGrid.HeaderStyle.ForeColor etc.  I'm not sure if you can get at the TDs directly but I don't know if you need this.

Regarding the BorderStyle, that should work fine.  Be careful you aren't overriding it somewhere.  I couldn't get BorderStyle to make much difference, but BorderColor worked fine.
0
 
alain123Author Commented:
ok thank you, i'll keep plaing with it..  still wasn't able to get the TD's on the c# code.. as for the border.. it's putting borders inside the grid too, not only outside as i wanted.. thanks
0
 
rlawleyCommented:
Well, if all else fails, this will put a border round the outside...

Grid.GridLines = GridLines.None;
Grid.Style.Add("border", "solid 1px black");
0
 
alain123Author Commented:
perfect thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.