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?Empl oyeeID=245 56&Subj=Pr eparing 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#
<a Href=AccountantHoursDetail
I want to make Test a hyperlink inside gridview but it dispaly plain html.
Any ideas
I m using C#
Set the HTMLEncode = "false" property and it will work
ASKER
i have autogenrated columns=true. Html Encode property of which control ???
it the gridview`s BoundField/coulum; you cannot use autogenrated columns=true
ASKER
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
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="Emp loyeeID"
DataNavigateUrlFormatStrin g="Account antHoursDe tail.aspx? EmployeeID ={0} &Subj=Preparing and Maintaining Accounting"
Text="test" />
bacause you could add a HyperLinkField has a coulum (EmployeeID is the column name), you dont have to manipulate the datatable.
<asp:HyperLinkField DataNavigateUrlFields="Emp
DataNavigateUrlFormatStrin
Text="test" />
in rowdatabound of gv
replace < with < and > with >
replace < with < and > with >
ASKER
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.Coun t;row++)
{
for(column=2;column<dt.Col umns.Count -1;column+ +)
{
Value=Convert.ToString(dt. Rows[row][ column]);
EmpID=Convert.ToString(dt. Rows[row][ 0]);
Subj=Convert.ToString(dt.C olumns[col umn].Colum nName);
str = "<a Href=AccountantHoursDetail .aspx?Empl oyeeID=" + EmpID.ToString() + "&Subj=" + Subj.ToString() + ">" + Value.ToString() + "</a>";
dt.Columns[column].ReadOnl y = false;
dt.Rows[row][column] = str.ToString();
after this i bind my datatable to the gridview.
string Value,EmpID,Subj,str;
int row,column;
for(row=0;row<dt.Rows.Coun
{
for(column=2;column<dt.Col
{
Value=Convert.ToString(dt.
EmpID=Convert.ToString(dt.
Subj=Convert.ToString(dt.C
str = "<a Href=AccountantHoursDetail
dt.Columns[column].ReadOnl
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)
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)
well you could pass multiple parameter, use the power of the comma
http://www.dotnetspider.com/resources/22216-Pass-Multiple-Query-String-using-HyperLinkField-asp-net.aspx
http://www.dotnetspider.com/resources/22216-Pass-Multiple-Query-String-using-HyperLinkField-asp-net.aspx
ASKER
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
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
ASKER
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
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
ASKER
Do you mean this replacement inside cell
cell.Text.Replace("<", "<");
cell.Text.Replace(">", ">");
but it does not seem to work either.
cell.Text.Replace("<", "<");
cell.Text.Replace(">", ">");
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
What if you loop the cell s controls??? ther may also the / char to replace..
Cell.Controls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.