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. - Add a gridview controls to the ASPX Page.
- Add AutoGenerateCol umns="false" in agridview controls
- Add a columns inside a gridview.
- Add a Bound field inside a columns.
- Add a HtmlEncode="fal se" to the bound column where you are using a HTML Tags.
- Provide a datasource to a GridView.
- Bind a GridView
Description:
Below is a sample code.
In ASPX Page - <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
-
<Columns>
-
<asp:BoundField DataField="Column1" HeaderText="Column1" />
-
<asp:BoundField HtmlEncode="false" DataField="Column2" HeaderText="Column2" />
-
</Columns>
-
</asp:GridView>
IN ASPX.CS File - protected void Page_Load(object sender, EventArgs e)
-
{
-
-
DataTable dtTable = CreateDataTable();
-
GridView1.DataSource = dtTable;
-
GridView1.DataBind();
-
-
}
-
DataTable CreateDataTable()
-
{
-
DataTable dtNew = new DataTable();
-
dtNew.Columns.Add("Column1");
-
dtNew.Columns.Add("Column2");
-
DataRow dr = dtNew.NewRow();
-
dr["Column1"] = "Test";
-
dr["Column2"] = "<p>My Address Line1</p><p>My Address Line2</p>";
-
dtNew.Rows.Add(dr);
-
return dtNew;
-
}
-
Summary
-
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.
1 3383
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();
-
DataRow dr;
-
abcd.Columns.Add(new DataColumn("Column1"));
-
abcd.Columns.Add(new DataCoumn("Column2"));
-
dr=abcd.NewRow();
-
dr["Column1"]="My Name";
-
dr["Column2"]="<p>My Address Line1</p><p>My Address Line2</p>";
-
abcd.AddRow(dr);
-
return(abcd);
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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?
|
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...
|
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...
|
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 (< ,
> ) the...
|
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...
| |
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>
|
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>
|
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....
|
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>
|
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();
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |