You are correct.  I am autogenerating the columns and your code worked:
 
// Set the 3rd header text to right alignment.
DataGridItem dgiHeader = (DataGridItem)grdAllLoans.Controls[0].Controls[0];
TableCell tc = dgiHeader.Cells[2];
tc.CssClass = "WhiteHeaderTextRightAligned";
 
Thanks for the help guys!
 
Mark

----- Original Message ----
From: Dean Fiala <[EMAIL PROTECTED]>
To: [email protected]
Sent: Friday, December 16, 2005 9:45:47 AM
Subject: Re: [AspNetAnyQuestionIsOk] Can I access cssstyle property of a header 
in a datagrid?

You must be autogenerating your columns in the grid, in which case the
columns collection is empty, and you need to get a little trickier.

You can still access the style in the code behind, it just takes some goofiness.

First you need to access the header DataGridItem

         DataGridItem dgiHeader  = (DataGridItem)dg.Controls[0].Controls[1];

//Note that the datagrid object has one child control of the type
DataGridTable, the items are children of this and not the datagrid
directly, hence the .Controls[0]
//If you are not using a pager, you might need to use
(DataGridItem)dg.Controls[0].Controls[0]; to access the header item,
just check the ItemType property

Then you access the cell you want to change and set the style


        TableCell tc  =dgiHeader.Cells[0];
        tc.CssClass = "SomeCSS";




On 12/16/05, Mark E <[EMAIL PROTECTED]> wrote:
> It's being called at the end of the Page_load method.  The DG is already 
> filled and *should* be accessible.  Or so I thought.
>
> Mark
>
> ----- Original Message ----
> From: Dean Fiala <[EMAIL PROTECTED]>
> To: [email protected]
> Sent: Friday, December 16, 2005 8:56:13 AM
> Subject: Re: [AspNetAnyQuestionIsOk] Can I access cssstyle property of a 
> header in a datagrid?
>
> When are you attemptting to call it?  It is possible you haven't
> created the grid or filled its columns yet.
>
> On 12/16/05, Mark E <[EMAIL PROTECTED]> wrote:
> > Dean,
> >
> > I'm getting the following error when I run the page:
> >
> > System.ArgumentOutOfRangeException: Index was out of range. Must be 
> > non-negative and less than the size of the collection. Parameter name: index
> >
> > I tried changing the index but all values throw the same error.  Any idea 
> > why?
> >
> > Thanks,
> > Mark
> >
> >
> > ----- Original Message ----
> > From: Dean Fiala <[EMAIL PROTECTED]>
> > To: [email protected]
> > Sent: Friday, December 16, 2005 8:35:47 AM
> > Subject: Re: [AspNetAnyQuestionIsOk] Can I access cssstyle property of a 
> > header in a datagrid?
> >
> > Yes.
> >
> > dg.Columns[2].HeaderStyle.CssClass = "SomeCSS";
> >
> > On 12/16/05, Mark E <[EMAIL PROTECTED]> wrote:
> > > Is something like this possible?
> > >
> > > datagrid.header.column[2].cssstyle = "SomeCSS";
> > >
> > > I need all my datagrid columns to have the same style except 1.  Since I 
> > > don't manually code my header columns, I need to do this in code-behind.  
> > > Is this possible?
> > >
> > > Thanks,
> > > Mark
> > >
> > > [Non-text portions of this message have been removed]
> > >
> > >
> > >
> > >
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > --
> > Dean Fiala
> > Very Practical Software, Inc
> > http://www.vpsw.com
> >
> >
> >
> > SPONSORED LINKS
> > Basic programming language Computer programming languages Programming 
> > languages
> > Java programming language
> >
> >
> >
> >
> >
> > YAHOO! GROUPS LINKS
> >
> >
> >  Visit your group "AspNetAnyQuestionIsOk" on the web.
> >
> >  To unsubscribe from this group, send an email to:
> >  [EMAIL PROTECTED]
> >
> >  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>
> --
> Dean Fiala
> Very Practical Software, Inc
> http://www.vpsw.com
>
>
>
>
> YAHOO! GROUPS LINKS
>
>
>  Visit your group "AspNetAnyQuestionIsOk" on the web.
>
>  To unsubscribe from this group, send an email to:
>  [EMAIL PROTECTED]
>
>  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>


--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com



SPONSORED LINKS 
Basic programming language Computer programming languages Programming languages 
Java programming language 





YAHOO! GROUPS LINKS 


 Visit your group "AspNetAnyQuestionIsOk" on the web.
  
 To unsubscribe from this group, send an email to:
 [EMAIL PROTECTED]
  
 Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 

[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
1.2 million kids a year are victims of human trafficking. Stop slavery.
http://us.click.yahoo.com/.QUssC/izNLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to