如何在Gridview中制作文本aligin?

Sur*_*har 9 asp.net

在Asp.Net中,当autogenerate列为true时,如何在列中应用文本对齐[left,center,right].在gridview的每一行中,文本显示在列的中心,我想显示在列的左侧.谢谢.

Har*_*aid 15

如果所有列都需要左对齐,请尝试使用以下语法

<RowStyle HorizontalAlign="Left"></RowStyle>
Run Code Online (Sandbox Code Playgroud)

另请查看这些MSDN资源,其中包含GridView格式的各种示例和Code Project文章,其中显示了AutoGenerated列scenerio的示例.


Sai*_*ala 9

对不起,这种情况只适用于autogeneratedcolumns = "false".请参阅编辑,autogeneratecolumns="true"如果要对齐列标题,请将其添加到BoundFiled:

 HeaderStyle-HorizontalAlign="Right"
Run Code Online (Sandbox Code Playgroud)

如果要对齐列的项,请将其添加到BoundField:

 ItemStyle-HorizontalAlign="Right" 
Run Code Online (Sandbox Code Playgroud)

编辑:

也可以尝试这一点单击gridView-> properties-> RowStyle:horizo​​ntal-align

<asp:gridview id="CustomersGridView" 
    datasourceid="CustomersSqlDataSource"  
Run Code Online (Sandbox Code Playgroud)
    autogeneratecolumns="true"
Run Code Online (Sandbox Code Playgroud)
    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>   
Run Code Online (Sandbox Code Playgroud)
          <td style="width:70%; text-align:right">
Run Code Online (Sandbox Code Playgroud)
            <asp:label id="CurrentPageLabel"
              forecolor="Blue"
              runat="server"/>

          </td>

        </tr>                    
      </table>

    </pagertemplate> 

  </asp:gridview>
Run Code Online (Sandbox Code Playgroud)

有关此链接的更多信息