Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I center the text in a datagrid

Posted on 2004-10-13
11
Medium Priority
?
167 Views
Last Modified: 2010-04-15
How can I center the text in my datagrid?
0
Comment
Question by:zstafa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 3

Expert Comment

by:yellowjetski
ID: 12304930
Add it on the HTML side on the aspx page
<ASP:TemplateColumn ItemStyle-HorizontalAlign=Center>

Here's some sample code

<ASP:DATAGRID id="drgList" runat="server" AutoGenerateColumns="False" BorderWidth="1px"
      width="100%" cellpadding="2" Cellspacing="0" GridLines="Horizontal" BorderColor="#E0DFE3">
      <ALTERNATINGITEMSTYLE CSSCLASS="gridItem2"></ALTERNATINGITEMSTYLE>
      <ITEMSTYLE CSSCLASS="gridItem2" VERTICALALIGN="Top"></ITEMSTYLE>
      <EDITITEMSTYLE VERTICALALIGN="Top"></EDITITEMSTYLE>
      <HEADERSTYLE CSSCLASS="tableHeader3"></HEADERSTYLE>
      <FOOTERSTYLE CSSCLASS="gridItem"></FOOTERSTYLE>
      <COLUMNS>
            <ASP:TemplateColumn ItemStyle-HorizontalAlign=Center>
                  <ITEMTEMPLATE>
                        <ASP:LABEL Runat="server" ID="Label2">
                              <%# DataBinder.Eval(Container.DataItem, "STUFF")%>
                        </ASP:LABEL>
                  </ITEMTEMPLATE>
            </ASP:TemplateColumn>
      </COLUMNS>
</ASP:DATAGRID>
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12304971
You can even do this in design view

Right Click on DataGrid --> Click on Property Builder --> Format --> Click on Items/Headers & Modify Horizontal Alignment as you want....

-tushar
0
 
LVL 3

Expert Comment

by:yellowjetski
ID: 12304991
However, if you have two columns and you want to right align one and left align the other one, you HAVE to do it from the HTML side.

If you only have one align requirement, you COULD do it from the Design side
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:tusharashah
ID: 12307568
Ofcorse you can..!!

Go to Property Builder --> Format --> Expand Columns --> Expand Column[n] --> Click on Header/Items/footer! & change allignments

Only time you cannot set Allignment for different column here in design view if they are AutoGenerated Columns. And if that is the case then you cannot even set alignment in HTML.

-tushar
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12307654
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12307713
And if it's a Windows Form then check out following article from MSDN to setup formatting for DataGrid..

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskformattingthedatagridatdesigntime.asp

-tushar
0
 
LVL 3

Author Comment

by:zstafa
ID: 12308586
Actually I'm not using asp at all. Just a datagrid in a form. Sorry for the mixup.
0
 
LVL 3

Author Comment

by:zstafa
ID: 12319721
The link to Microsoft about setting up formatting for datagrids doesn't say anything about text alignment. Does anyone know of any way i could find out how to do this? Thanks
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 2000 total points
ID: 12320094
0
 
LVL 3

Author Comment

by:zstafa
ID: 12328012
Thanks alot for your help. Adding the tablestyles and the columstyles allowed me to control the alignment of each column.
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12328104
Nice to have you going zstafa!

Thanks for A:)

-tushar
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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