473,549 Members | 2,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect HTML Tags in DataColumn

17 New Member
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 AutoGenerateCol umns="false" in agridview controls
  3. Add a columns inside a gridview.
  4. Add a Bound field inside a columns.
  5. Add a HtmlEncode="fal se" 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 3383
AlmalynC88
3 New Member
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
3764
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? If not, is there an easy way to strip the html tags from the <definition> content before inserting the content into the meta tag?
13
2313
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 getNodeValue(), they both returns null also. I know <br /> and <br></br> are the same from the xml spec. Is there any way to tell the different...
15
6007
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 use. http://www.interactivetools.com/products/htmlarea/ This only works with IE5.5+. What I need to do is to take this html formatted text and only...
18
10448
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 close the STRONG tag the same way, my text appears in bold. No problem. When I do the same things with the corresponding HTML tags (&lt; , &gt; ) the...
1
1423
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 open in Design View and come back, my HTML view loses all its code formatting. 2. ASP.Net has been inserting "DESGNTIMESP" tags in random places in...
4
4147
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
3078
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 RegularExpressionValidator that will allow certain HTML tags: <a>, <b>, <blockquote>, <br>, <i>, <img>, <li>, <ol>, <p>, <quote>, <ul>
17
1783
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 html format, but it obviously had html tags. Now, a php or a perl/ cgi or a javascript ng is always going to had html tags in posted messages....
1
2974
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 doesn't exist. i.e. <DOC> <title>Book title</title> <p>This is a paragrap</p> <header>Header</header>
2
3208
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: DataTable abcd = new DataTable();
0
7527
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7967
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7485
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7819
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.