Solved

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

Posted on 2004-08-18
9
381 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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