Reputation: 157
i want use space inside string, i use this code:
var lst = Article.Select(a => new {a.ID, Name = " " + a.Name}).ToList();
gv.DataSource = lst.ToList();
gv.DataBind();
but its not working, with this code display name = " "Name.
and use this code:
var lst = Article.Select(a => new {a.ID, Name = " " + a.Name}).ToList();
gv.DataSource = lst.ToList();
gv.DataBind();
and with this code display name = " "Name.
please help me
Edit:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false">
<Columns>
...
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" ItemStyle-Width="300px" ItemStyle-HorizontalAlign="Right"></asp:BoundField>
...
</asp:GridView>
Edit2:
Answer:
Thank you to all.
Upvotes: 0
Views: 334
Reputation: 38683
Try this sample way
a.Name.ToString().PadLeft(10," ")
Edit Try this
a.Name.PadLeft(10,' ')
Upvotes: 0
Reputation: 263723
will this work?
string constructor that constructs a string from a character a repeat
count:
var lst = Article.Select(a => new {a.ID, Name = new string(' ', 8) + a.Name})
.ToList();
UPDATE 1
set property, HtmlEncode=False
<asp:BoundField DataField="Name" HtmlEncode="False" />
and enclosed the value with <pre>
tag
var lst = Article.Select(a => new {a.ID, Name = "<pre> </pre>" + a.Name})
.ToList();
Upvotes: 2
Reputation: 717
I am assuming the gv is an asp.net gridview control and that all your whitespace is being merged when displayed in a browser.
So, try something like this
<asp:BoundField DataField="Name">
<ItemStyle CssClass="NameCol" />
</asp:BoundField>
and in your css
..NameCol
{
padding-left:50px;
}
Upvotes: 1