我有一个gridview控件,我在其中显示数据集中的记录。 数据集包含根据需要填充空间的记录。 我试图在这篇文章中按照ASP.NET GridView中的一个列的编程方式更改样式(填充)
但是,当我在gridview中显示它们时,记录显示左对齐。
如何显示空间填充记录?
<asp:GridView runat="server" ID="gvCustomer" Visible="false" Width="350px" CellSpacing="1" ClientIDMode="Static" CellPadding="2" AutoGenerateColumns="false" OnRowDataBound="gvCustomer_OnRowDataBound" ViewStateMode="Enabled" EmptyDataText=""> <Columns> <asp:BoundField DataField="CustomerName" ControlStyle-Width="225px" HeaderStyle-HorizontalAlign="Center" HeaderText="Customers" /> </Columns> </asp:GridView>I have a gridview control where I am displaying records from a dataset. The dataset contains records that are space padded as needed. I am trying to follow the solution in this post programatically change style (padding) of a column in ASP.NET GridView
However, when I display them in the gridview, the records show left aligned.
How can I display space padded records?
<asp:GridView runat="server" ID="gvCustomer" Visible="false" Width="350px" CellSpacing="1" ClientIDMode="Static" CellPadding="2" AutoGenerateColumns="false" OnRowDataBound="gvCustomer_OnRowDataBound" ViewStateMode="Enabled" EmptyDataText=""> <Columns> <asp:BoundField DataField="CustomerName" ControlStyle-Width="225px" HeaderStyle-HorizontalAlign="Center" HeaderText="Customers" /> </Columns> </asp:GridView>最满意答案
您需要做的是将BoundField更改为TemplateField ,并使用RowDataBound事件将所有空格替换为 。 HTML不会以您希望的方式处理空格,这就是您需要非破坏空间( )字符的原因。
或者,如果您真的想使用BoundField ,请修改您的SQL查询以使用 替换空格 和绑定。
What you'll have to do is change your BoundField to be a TemplateField, and use a RowDataBound event to replace all spaces with . HTML does not deal with spaces in the way you would like, which is why you'll need the non-breaking-space ( ) character.
Or if you really would like to use a BoundField, modify your sql query to replace spaces with and bind.
更多推荐
发布评论