显示在asp.net gridview的空间填充记录 [英] displaying space padded records in asp.net gridview
问题描述
我在那里,我从一个数据集显示记录的GridView控件。该数据集包含的空间填充需要的记录。我想跟随在这个岗位编程改变列的样式(填充)在ASP.NET GridView的
然而,当我在GridView显示它们,记录显示左对齐。
我怎么能施展的空间填充记录?
< ASP:GridView控件=服务器ID =gvCustomer可见=假
宽度=350像素CELLSPACING =1的ClientIDMode =静态CELLPADDING =2
的AutoGenerateColumns =false的OnRowDataBound =gvCustomer_OnRowDataBound
ViewStateMode =已启用EmptyDataText =>
<柱体和GT;
< ASP:BoundField的数据字段=客户名称ControlStyle-WIDTH =225pxHeaderStyle-HorizontalAlign =中心的HeaderText =客户/>
< /专栏>
< / ASP:GridView的>
你必须做的是改变你的的BoundField
是一个模板列
,并使用的RowDataBound
事件来替换&放所有的空格; NBSP;
。 HTML不应对你会喜欢的方式,这就是为什么你需要非换空间(&放大器; NBSP;
)的空间。性格
或者,如果你真的想用一个的BoundField
,修改你的SQL查询与&放大器来代替空间; NBSP;
和绑定。
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>
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.
这篇关于显示在asp.net gridview的空间填充记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!