Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am using Gridview to show some data, but i am facing some problem in aligning the text in grid view boundfield.

I have to justify the text in gridview column, i am using below code

VB
<asp:BoundField DataField="Description" HeaderText="Description" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="Justify" />



But it is not working. Any suggestion most welcome
Posted
Updated 18-Jun-21 8:53am
Comments
Karthik Harve 14-Jun-12 4:26am    
May be the CSS class which you have applied to the grid, may have different text alignment. check your css class.
Vani Kulkarni 14-Jun-12 4:44am    
I agree with Karthik. Please check your CSS.

 
Share this answer
 
Comments
Dennis Romero Xavier 7-Dec-17 9:44am    
I tried this but it shows error.
XML
<asp:BoundField DataField="MC" HeaderText="MC" SortExpression="MC">
     <ItemStyle HorizontalAlign="Center" />
</asp:BoundField>


Just post the answer, instead of a hyperlink to another website!!
 
Share this answer
 
Comments
CHill60 15-Sep-15 9:28am    
It's fairly common to just post links. Firstly, there may be other discussions and/or alternatives discussed. Secondly it encourages the understanding that most of the questions asked here could be answered by the OP themselves with a little research.
If you are going to provide the answer then it's also fairly common to use the code from the OPs question and explain the differences - e.g. HeaderText should be "Description" not "MC". How does SortExpression help with justification of text, etc
if you don't want use cssClas you can use this.

col5.ItemStyle.HorizontalAlign = 3

1 to Left, 2 to Center and 3 to Right
 
Share this answer
 
Comments
Richard Deeming 21-Jun-21 10:41am    
Setting the HorizontalAlign property is precisely what the previous two solutions suggested.

Using the numeric value of the enum, rather than the named value, simply makes the code less readable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900