我GrdiView
在 asp.net 页面上有一个。我将数据源设置为DataTable
. 如果单元格中的值是字符串类型,我需要设置HorizontalAlign
为左,否则如果它是小数,我希望它向右对齐。请让我知道如何实现这一点。的代码GridView
如下:
<asp:GridView ID="gridViewReport" runat="server" Height="1px" OnRowDataBound="UsersGVRowDataBound" GridLines="both" Style="z-index: 100;
left: 2px; position: absolute; top: 1px; " Width="939px" CellPadding="4" ForeColor="#333333" AllowSorting="True" OnSorting="gridViewReport_Sorting" Font-Names="Verdana" Font-Size="12px" OnSelectedIndexChanged="gridViewReport_SelectedIndexChanged1">
<AlternatingRowStyle BackColor="White" />
<RowStyle HorizontalAlign="Left" BackColor="#EFECE5" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C0F6C0" ForeColor="#333333" Font-Bold="True" />
<HeaderStyle BackColor="#CDE472" Font-Bold="True" ForeColor="DarkGreen" HorizontalAlign ="Left" Font-Italic="False" Font-Names="Verdana" Font-Overline="False"/>
<EditRowStyle BackColor="#EAEAAE" />
</asp:GridView>
另外,设置的代码DataSource
如下:
gridViewReport.DataSource = _reportTable;
gridViewReport.DataBind();