how to render html inside gridview cells

In my gridview cells i dont want to show html rather dispaly the output.e.g.
<a Href=AccountantHoursDetail.aspx?EmployeeID=24556&Subj=Preparing and Maintaining Accounting Records>Test</a>
I want to make Test  a hyperlink inside gridview but it dispaly plain html.
Any ideas
I m using C#
mmalik15Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Obadiah ChristopherCommented:
Set the HTMLEncode = "false" property and it will work
0
mmalik15Author Commented:
i have autogenrated columns=true. Html Encode property of which control ???
0
David RobitailleAnalyst ProgrammerCommented:
it the gridview`s BoundField/coulum; you cannot use autogenrated columns=true
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mmalik15Author Commented:
I m adding html link tag in the datatable and then binding it to gridview & in the gridview autogeneratedcolumns=true. But i want gridview to show the links
Thanks
0
David RobitailleAnalyst ProgrammerCommented:
does the link is the content (data) from a database column column???
bacause you could add a HyperLinkField has a coulum (EmployeeID is the column name), you dont have to manipulate the datatable.

<asp:HyperLinkField DataNavigateUrlFields="EmployeeID"
DataNavigateUrlFormatString="AccountantHoursDetail.aspx?EmployeeID={0} &Subj=Preparing and Maintaining Accounting"
Text="test" />
0
Obadiah ChristopherCommented:
in rowdatabound of gv

replace < with < and > with >
0
mmalik15Author Commented:
no i have to dynamically create the URL after i get the results from my database. Here is code

 string Value,EmpID,Subj,str;
            int row,column;
            for(row=0;row<dt.Rows.Count;row++)
            {
                for(column=2;column<dt.Columns.Count-1;column++)

                {
                 
                    Value=Convert.ToString(dt.Rows[row][column]);
                    EmpID=Convert.ToString(dt.Rows[row][0]);
                    Subj=Convert.ToString(dt.Columns[column].ColumnName);

                    str = "<a Href=AccountantHoursDetail.aspx?EmployeeID=" + EmpID.ToString() + "&Subj=" + Subj.ToString() + ">" + Value.ToString() + "</a>";
                                                       
                    dt.Columns[column].ReadOnly = false;
                   
                    dt.Rows[row][column] = str.ToString();

after this i bind my datatable to the gridview.
0
David RobitailleAnalyst ProgrammerCommented:
informaniac, i think you should use the code snippet...
infomaniac, is solution is if your data is html formated, mine (the HyperLinkField ) is if you just what to add a link to each row the grid view (and keep autogeneratedcolumns=true)
0
David RobitailleAnalyst ProgrammerCommented:
0
mmalik15Author Commented:
Thanks but
I can not add hyperlink field because i have to dynamically create the parameters and then over write my existing datatable and then i bind this datatable to the gridview
0
mmalik15Author Commented:
informaniac can you please give me an example
0
David RobitailleAnalyst ProgrammerCommented:
well, now i see exacly what you whant ton do...
i think you will find that one interesting. you will be able to use the replace function to replace the HTML code for < and > using this.
http://www.codeproject.com/KB/webforms/FrmtAutoGenClmnASPNETGrid.aspx
0
mmalik15Author Commented:
Do you mean this replacement inside cell

 cell.Text.Replace("<", "&lt");
 cell.Text.Replace(">", "&gt");

but it does not seem to work either.
0
David RobitailleAnalyst ProgrammerCommented:
humm, i thoug that would work.
What if you loop the cell s controls??? ther may also the / char to replace..
Cell.Controls
0
prairiedogCommented:
Two ways to do this:
1. Use GridView's RowDataBound event handler to contruct those hyper links instead of in DataTable.
string url = "<a href='www.mysite.com'>Site</a>";
e.Row.Cells[i].Text = url; //<===Change i to the cell containing URL
2. If you need to construct those URL's in DataTable, then in the RowDataBound, for each URL cell, you will need to call HtmlDecode to make it a clickable URL:

e.Row.Cells[i].Text = HttpUtility.HtmlDecode(e.Row.Cells[i].Text);
Change "i" to the actual index of the URL cell. If you have more than one cell containing URL, then you need to use the above line for each cell.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.