Reputation: 65
I have a DataTable
which is populated from database. In one of its column i have comma separated values. I want to remove comma and put the line break so that when i bind it to the GridView
it shows line breaks instead of comma seperated values.
Upvotes: 1
Views: 3926
Reputation: 460158
A simple approach for an ASP.NET GridView
:
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="Values">
<ItemTemplate>
<asp:Literal runat="server" id="Values"
Text='<%# string.Join("<br />", Eval("Values").ToString().Split(new []{","},StringSplitOptions.None)) %>'>
</asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Bound a DataTable
with some numbers to it, here's the result:
Of yourse it's also possible to use a nested GridView
and bind it in RowDataBound
of the outer grid. But that's a more difficult approach with some drawbacks which might be too much in this case.
Upvotes: 1
Reputation: 9126
Try the below...
If it is windows Application then try the below...
yourString = yourString.Replace(",",System.Environment.NewLine)
Upvotes: 2