在asp.net gridview中显示空格填充记录(displaying space padded records in asp.net gridview)

编程入门 行业动态 更新时间:2024-10-26 16:35:42
在asp.net gridview中显示空格填充记录(displaying space padded records in asp.net gridview)

我有一个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事件将所有空格替换为&nbsp; 。 HTML不会以您希望的方式处理空格,这就是您需要非破坏空间( &nbsp; )字符的原因。

或者,如果您真的想使用BoundField ,请修改您的SQL查询以使用&nbsp;替换空格&nbsp; 和绑定。

What you'll have to do is change your BoundField to be a TemplateField, and use a RowDataBound event to replace all spaces with &nbsp;. HTML does not deal with spaces in the way you would like, which is why you'll need the non-breaking-space (&nbsp;) character.

Or if you really would like to use a BoundField, modify your sql query to replace spaces with &nbsp; and bind.

更多推荐

本文发布于:2023-07-21 09:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208973.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空格   gridview   net   asp   records

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!