Solved

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

Posted on 2004-08-18
9
371 Views
Last Modified: 2012-06-27
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
 
0
Comment
Question by:HStrix
  • 4
  • 3
  • 2
9 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 250 total points
ID: 11838584
Hi,

if you mean that the header text should not show as
UserId
but as
U
s
e
r
I
D

you should do that through the ItemDataBound event like

        If e.Item.ItemType = ListItemType.Header Then
            Dim index As Integer
            Dim headerText As String
            For index = 0 To e.Item.Cells(0).Text.Length - 1
                headerText = headerText & e.Item.Cells(0).Text.Substring(index, 1) & "<br>"
            Next
            e.Item.Cells(0).Text = headerText
        End If

Regards,
B..M
0
 

Author Comment

by:HStrix
ID: 11838653
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>


0
 
LVL 3

Expert Comment

by:alexpreston
ID: 11838687
       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
0
 
LVL 3

Assisted Solution

by:alexpreston
alexpreston earned 250 total points
ID: 11838698
oops, messed that up

 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
            e.Item.Cells(cellCount).Text = headerText
Next
        End If
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

Expert Comment

by:mmarinov
ID: 11838708
yes because i show you the way
you have to do that for every header text

Regards,
B..M
0
 
LVL 3

Expert Comment

by:alexpreston
ID: 11838757
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!)
0
 

Author Comment

by:HStrix
ID: 11838762
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
---
0
 
LVL 3

Expert Comment

by:alexpreston
ID: 11838773
Oh dear, forgot to reset headerText too. I'm bad. :-)
0
 

Author Comment

by:HStrix
ID: 11838785
OK, thank you both again for your help.

  HStrix
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now