Link to home
Start Free TrialLog in
Avatar of mmalik15
mmalik15

asked on

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#
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Set the HTMLEncode = "false" property and it will work
Avatar of mmalik15
mmalik15

ASKER

i have autogenrated columns=true. Html Encode property of which control ???
it the gridview`s BoundField/coulum; you cannot use autogenrated columns=true
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
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" />
in rowdatabound of gv

replace < with < and > with >
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.
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)
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
informaniac can you please give me an example
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
Do you mean this replacement inside cell

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

but it does not seem to work either.
humm, i thoug that would work.
What if you loop the cell s controls??? ther may also the / char to replace..
Cell.Controls
ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial