• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

How do I center the text in a datagrid

How can I center the text in my datagrid?
0
zstafa
Asked:
zstafa
  • 6
  • 3
  • 2
1 Solution
 
yellowjetskiCommented:
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
 
tusharashahCommented:
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
 
yellowjetskiCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
tusharashahCommented:
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
 
tusharashahCommented:
0
 
tusharashahCommented:
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
 
zstafaAuthor Commented:
Actually I'm not using asp at all. Just a datagrid in a form. Sorry for the mixup.
0
 
zstafaAuthor Commented:
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
 
zstafaAuthor Commented:
Thanks alot for your help. Adding the tablestyles and the columstyles allowed me to control the alignment of each column.
0
 
tusharashahCommented:
Nice to have you going zstafa!

Thanks for A:)

-tushar
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now