Link to home
Start Free TrialLog in
Avatar of HStrix
HStrix

asked on

Asp.Net: how-to make datagrid headers appearing vertically

Hello experts,
in my Asp.Net (vb.net) web application is a datagrid as follows:
---
<asp:datagrid id="dgX" OnItemCommand="showX" > 
  <Columns>
    <asp:BoundColumn DataField="UserID" HeaderText="UserID" />
  </Columns>
</asp:datagrid>
---
Now I want to ensure that the HeaderText for the sample field appears in the datagrid vertically.
The text in the datagrid's body shall remain appearing horizontally.
How can I do this?

If anyone knows a solution please supply appropriate [snippet] information.

   Thank you very much!

     HStrix
 
ASKER CERTIFIED SOLUTION
Avatar of mmarinov
mmarinov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HStrix
HStrix

ASKER

Thank you mmarinov,
that works, but only for the first element of the datagrid.

<asp:datagrid id="dgX" OnItemCommand="showX" > 
  <Columns>
    <asp:BoundColumn DataField="UserID" HeaderText="UserID" />            <== that works
    <asp:BoundColumn DataField="UserName" HeaderText="UserName" />  <== that doesn't work
  </Columns>
</asp:datagrid>


       If e.Item.ItemType = ListItemType.Header Then
            Dim index As Integer
            Dim headerText As String
For cellCount = 0 To e.Item.Cells.Count
            For index = 0 To e.Item.Cells(cellCount).Text.Length - 1
                headerText = headerText & e.Item.Cells(cellCount).Text.Substring(index, 1) & "<br>"
            Next
Next
            e.Item.Cells(0).Text = headerText
        End If
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes because i show you the way
you have to do that for every header text

Regards,
B..M
Yes. Once you know to use the  ItemDataBound event it's pretty easy. Although I think I messed it up again, should have used  "e.Item.Cells.Count - 1".

(it's too early in the morning!)
Avatar of HStrix

ASKER

Thank you very much mmarinow and alexpreston.
I modified the code to
---
        If e.Item.ItemType = ListItemType.Header Then
            Dim cellCount As Integer
            Dim index As Integer
            Dim headerText As String
            For cellCount = 0 To e.Item.Cells.Count - 1
                headerText = ""
                For index = 0 To e.Item.Cells(cellCount).Text.Length - 1
                    headerText = headerText & e.Item.Cells(cellCount).Text.Substring(index, 1) & "<br>"
                Next
                e.Item.Cells(cellCount).Text = headerText
            Next
        End If
---
Oh dear, forgot to reset headerText too. I'm bad. :-)
Avatar of HStrix

ASKER

OK, thank you both again for your help.

  HStrix