In Asp.Net, how to apply text align [left,center,right] in a column, when autogenerate column is true. In every row of gridview the text is displayed in center of the column, i want to display in left side of the column. Thank you.
Sorry, this case will work only when autogeneratedcolumns = "false"
. See the edit for the autogeneratecolumns="true"
If you want to align the header of the column add this to the BoundFiled:
HeaderStyle-HorizontalAlign="Right"
And if you want to align the item of the column add this to the BoundField:
ItemStyle-HorizontalAlign="Right"
EDIT:
Also try this too Click on the gridView->properties->RowStyle:horizontal-align
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
allowpaging="true"
ondatabound="CustomersGridView_DataBound"
runat="server">
<pagerstyle forecolor="Blue"
backcolor="LightBlue"/>
<pagertemplate>
<table width="100%">
<tr>
<td style="width:70%">
<asp:label id="MessageLabel"
forecolor="Blue"
text="Select a page:"
runat="server"/>
<asp:dropdownlist id="PageDropDownList"
autopostback="true"
onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
runat="server"/>
</td>
<td style="width:70%; text-align:right">
<asp:label id="CurrentPageLabel"
forecolor="Blue"
runat="server"/>
</td>
</tr>
</table>
</pagertemplate>
</asp:gridview>
more info on this link
Try using below syntax if all the columns needs to left aligned
<RowStyle HorizontalAlign="Left"></RowStyle>
Also check these MSDN resource which has various examples for GridView formatting and Code Project article which shows examples for AutoGenerated
Columns scenerio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With