Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-18
9
Medium Priority
?
391 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 1000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Assisted Solution

by:alexpreston
alexpreston earned 1000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

926 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