Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make text aligin in Gridview?

Tags:

asp.net

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.

like image 674
Surya sasidhar Avatar asked Oct 24 '11 04:10

Surya sasidhar


Video Answer


2 Answers

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

like image 105
Sai Kalyan Kumar Akshinthala Avatar answered Oct 28 '22 00:10

Sai Kalyan Kumar Akshinthala


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.

like image 27
Harsh Baid Avatar answered Oct 28 '22 00:10

Harsh Baid