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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).Te xt.Length - 1
headerText = headerText & e.Item.Cells(cellCount).Te xt.Substri ng(index, 1) & "<br>"
Next
Next
e.Item.Cells(0).Text = headerText
End If
Dim index As Integer
Dim headerText As String
For cellCount = 0 To e.Item.Cells.Count
For index = 0 To e.Item.Cells(cellCount).Te
headerText = headerText & e.Item.Cells(cellCount).Te
Next
Next
e.Item.Cells(0).Text = headerText
End If
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yes because i show you the way
you have to do that for every header text
Regards,
B..M
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!)
(it's too early in the morning!)
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).Te xt.Length - 1
headerText = headerText & e.Item.Cells(cellCount).Te xt.Substri ng(index, 1) & "<br>"
Next
e.Item.Cells(cellCount).Te xt = headerText
Next
End If
---
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).Te
headerText = headerText & e.Item.Cells(cellCount).Te
Next
e.Item.Cells(cellCount).Te
Next
End If
---
Oh dear, forgot to reset headerText too. I'm bad. :-)
ASKER
OK, thank you both again for your help.
HStrix
HStrix
ASKER
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>