-1

I am using DataTable to populate data in GridView in ASP.NET I am trying to place a line break in a cell inside the DataGrid View I used

   "data1+<br>+data2"

to place a line break.I am manipulating this data from C# which is being generated dynamically. Because of HTML encoding
is replaced as

 lt;brgt;

So please tell me how to disable that html encoding if possible for that gridView.

4
  • Use <asp:TemplateField/> Commented Jul 3, 2014 at 12:30
  • @Bharadwaj I didnot get you Commented Jul 3, 2014 at 12:30
  • @codeCaster Is this a duplicate? Can you show me the answer then? Commented Jul 3, 2014 at 12:41
  • Click the link on top of your question, the duplicate contains 4 answers. If you think none of them answers your question, please update your question with how exactly you print the data to your DataGridView. Commented Jul 3, 2014 at 12:42

2 Answers 2

1

There is a option available in Boundfield of your grid view. HtmlEncode="false"

The code in my case

<asp:BoundField DataField="timeStamp" HeaderText="timeStamp" HtmlEncode="false" />
Sign up to request clarification or add additional context in comments.

2 Comments

I didnot find the BoundField in GridView properties I am using Visual Studio 2010
BoundField is part of Gridview columns. Can you post the part of your code, to get a clear picture?
0

TemplateField allows you to add html inside a cell, as

<asp:GridView ID="gv" runat="server" AutogenerateColumns = "false">
 <columns>
    <asp:BoundField DataField="col_name" HeaderText="Header"/>
    <asp:TemplateField>
      <ItemTemplate>
         '<%#Eval("data1")%>'
          <br/>
         '<%#Eval("data2")%>'
      </ItemTemplate>
    </asp:TemplateField>
 <columns>
</asp:GridView>

8 Comments

How can I place it inside a data cell?
TemplateField itself a data cell.
I think you are populating using BoundedField, replace it with the above code, if you have data1 and data2 as separate columns in your datatable.
wHERE CAN i FIND THAT IN MY vISUAL sTUDIO under the designer->grid view->properties?
WOW. Switch to Source mode for your .aspx or .ascx file. For GridView, set AutogenerateColumns = "false". Then add all coloumns you want, including the above.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.