zstafa
asked on
How do I center the text in a datagrid
How can I center the text in my datagrid?
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
Right Click on DataGrid --> Click on Property Builder --> Format --> Click on Items/Headers & Modify Horizontal Alignment as you want....
-tushar
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
If you only have one align requirement, you COULD do it from the Design side
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
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
Check out this Article from MSDN on DataGrid formatting..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskSpecifyingGridItemFormatInDataGridWebControl.asp
-tushar
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskSpecifyingGridItemFormatInDataGridWebControl.asp
-tushar
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
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskformattingthedatagridatdesigntime.asp
-tushar
ASKER
Actually I'm not using asp at all. Just a datagrid in a form. Sorry for the mixup.
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks alot for your help. Adding the tablestyles and the columstyles allowed me to control the alignment of each column.
Nice to have you going zstafa!
Thanks for A:)
-tushar
Thanks for A:)
-tushar
<ASP:TemplateColumn ItemStyle-HorizontalAlign=
Here's some sample code
<ASP:DATAGRID id="drgList" runat="server" AutoGenerateColumns="False
width="100%" cellpadding="2" Cellspacing="0" GridLines="Horizontal" BorderColor="#E0DFE3">
<ALTERNATINGITEMSTYLE CSSCLASS="gridItem2"></ALT
<ITEMSTYLE CSSCLASS="gridItem2" VERTICALALIGN="Top"></ITEM
<EDITITEMSTYLE VERTICALALIGN="Top"></EDIT
<HEADERSTYLE CSSCLASS="tableHeader3"></
<FOOTERSTYLE CSSCLASS="gridItem"></FOOT
<COLUMNS>
<ASP:TemplateColumn ItemStyle-HorizontalAlign=
<ITEMTEMPLATE>
<ASP:LABEL Runat="server" ID="Label2">
<%# DataBinder.Eval(Container.
</ASP:LABEL>
</ITEMTEMPLATE>
</ASP:TemplateColumn>
</COLUMNS>
</ASP:DATAGRID>