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
BoundFieldto be aTemplateField, and use aRowDataBoundevent 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.