473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,399 developers and data experts.

How to detect HTML Tags in DataColumn

This code will help for the beginners, who want to learn, how to detect a HTML Tags inside a gridview.

Before getting to the code I will give a small introduction how to work with gridview with HTMl Tags.
  1. Add a gridview controls to the ASPX Page.
  2. Add AutoGenerateColumns="false" in agridview controls
  3. Add a columns inside a gridview.
  4. Add a Bound field inside a columns.
  5. Add a HtmlEncode="false" to the bound column where you are using a HTML Tags.
  6. Provide a datasource to a GridView.
  7. Bind a GridView

Description:

Below is a sample code.

In ASPX Page
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
  2.             <Columns>
  3.                 <asp:BoundField  DataField="Column1" HeaderText="Column1" />
  4.                 <asp:BoundField HtmlEncode="false" DataField="Column2" HeaderText="Column2" />
  5.             </Columns>
  6.         </asp:GridView>
IN ASPX.CS File
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.  
  4.             DataTable dtTable = CreateDataTable();
  5.             GridView1.DataSource = dtTable;
  6.             GridView1.DataBind();
  7.  
  8.         }
  9.     DataTable CreateDataTable()
  10.         {
  11.             DataTable dtNew = new DataTable();
  12.             dtNew.Columns.Add("Column1");
  13.             dtNew.Columns.Add("Column2");
  14.             DataRow dr = dtNew.NewRow();
  15.             dr["Column1"] = "Test";
  16.             dr["Column2"] = "<p>My Address Line1</p><p>My Address Line2</p>";
  17.             dtNew.Rows.Add(dr);
  18.             return dtNew;
  19.         }
  20. Summary
  21.  
There are many topics to learn with ASP.Net. I have covered a small portion hope this will helps all the beginners to startup. Please give your feedback and suggestion.
Mar 21 '11 #1
1 3374
In may page, i am assigning DataTable to a GridView as follows:

Expand|Select|Wrap|Line Numbers
  1. GridView1.DataSource = GetDataTable();
  2. GridView1.DataBind();
Now,the definition of GetDataTable is as follows:

Expand|Select|Wrap|Line Numbers
  1. DataTable abcd = new DataTable();
  2. DataRow dr;  
  3. abcd.Columns.Add(new DataColumn("Column1"));
  4. abcd.Columns.Add(new DataCoumn("Column2"));  
  5. dr=abcd.NewRow();  
  6. dr["Column1"]="My Name";
  7. dr["Column2"]="<p>My Address Line1</p><p>My Address Line2</p>";  
  8. abcd.AddRow(dr);  
  9. return(abcd);
  10.  
dont bother about code syntax or functions, I just dont have actual code right now.Its on the similar lines...

My question is, when i see GridView, It prints <p></p> in Column2 as it is.. it doesnt consider those tags as HTML tags...

I want DataColumn to consider those tags as HTML, so that my address gets printed on two different lines but in same column.

If you guys have any other way to work around... just the thing is that I must assign DataTable to GridView.
Mar 2 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Donald Firesmith | last post by:
Are html tags allowed within meta tags? Specifically, if I have html tags within a <definition> tag within XML, can I use the definition as the content within the <meta content="description> tag? ...
13
by: vega | last post by:
How do I detect empty tags if I have the DOM document? For example: <br /> and <br></br> I tried org.w3c.dom.Node.getFirstChild(), it returns null for both <br /> and <br></br> I also tried...
15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
18
by: Robert Bowen | last post by:
Hello peeplez. I have an odd problem. When I put the ANSI symbol for "less than" ("<"), the word STRONG and then the ANSI symbol for "greater than" (">") in my web page, followed by some text, then...
1
by: coder10 | last post by:
Two things 1. Why does ASP.Net not respect code formatting for the HTML tags. I mean, when I write my HTML, I try to use appropriate tabs and spaces and lines beween my tags, but when I save and...
4
by: Spondishy | last post by:
Hi, I'm looking for help with a regular expression and c#. I want to remove all tags from a piece of html except the following. <a> <b> <h1> <h2>
10
by: Barry L. Camp | last post by:
Hi all... hope someone can help out. Not a unique situation, but my search for a solution has not yielded what I need yet. I'm trying to come up with a regular expression for a...
17
by: V S Rawat | last post by:
I joined this ng and tried to post my first message that had a small php code (HTML and all). my newsserver aioe.net rejected the post saying "HTML Tags". My message was in text format, not in...
1
by: SM | last post by:
Hello, I have a couple of XML files that represent articles. Each XML file is unique. Meaning that overall the structure is the same but some tags in the xml file are not in the same place or...
2
by: zacksoniar | last post by:
Hi all, In may page, i am assigning DataTable to a GridView as follows: GridView1.DataSource = GetDataTable(); GridView1.DataBind(); Now,the definition of GetDataTable is as follows: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.