Home All Groups Group Topic Archive Search About

Datagrid ... is this the control from hell?

Author
11 May 2005 8:00 PM
Bill
I am trying to programatically alter the style of x column headings on a
datagrid.  can someone point me in the direction of anything that could help
me determine how this is done?

I have:
- retreived my data
- processed my data
- displayed my data

My desired result would be something along the lines of:

.... <td>Heading 1</td><td class=NewStyle>Heading 2</td>...

I will know what headings I need to alter at the data processing (business)
layer.  I will send the information to the web page along with the data to be
displayed.  What I can't determine how to do is programatically target a
specific column name.

Any assistance will help keep my sanity.

Author
11 May 2005 8:49 PM
vMike
Show quote Hide quote
"Bill" <B***@discussions.microsoft.com> wrote in message
news:E40F3AB9-68E2-479A-BF2C-AA61927AB9CF@microsoft.com...
> I am trying to programatically alter the style of x column headings on a
> datagrid.  can someone point me in the direction of anything that could
help
> me determine how this is done?
>
> I have:
> - retreived my data
> - processed my data
> - displayed my data
>
> My desired result would be something along the lines of:
>
> ... <td>Heading 1</td><td class=NewStyle>Heading 2</td>...
>
> I will know what headings I need to alter at the data processing
(business)
> layer.  I will send the information to the web page along with the data to
be
> displayed.  What I can't determine how to do is programatically target a
> specific column name.
>
> Any assistance will help keep my sanity.
>
>
Can you turn off headings for the datagrid and create your own heading
control with the styles you need?

Mike
Author
12 May 2005 5:38 PM
Bill
I found a solution.

When the data source is bounded to the datagrid control I can use the
ItemDataBound event to then interrogate what item type is being bounded. 
i.e.:

    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
        If e.Item.ItemType = ListItemType.Header Then

        End If
    End Sub

I can then:

e.Item.Cells(0).CssClass = "NewClassName"

Because I know what column names I want to adjust (in the bl layer at run
time) I can pass that dynamic information back and rip through it (replacing
the e.Item.Cells(Integer) with the particular cell number).

Cheers