简体   繁体   中英

GridView w/ dynamic columns - displaying html

I'm trying to display tabular data where the columns are dynamic. I'm currently using a GridView w/ AutoGenerateColumns set to true.

Everything "works" but any html in my values shows as an html string - not as rendered html. IE: shows the html to create the link instead of showing a link.

Or maybe there's a better way to accomplish this task.

More nitty gritty: I'm showing "sales projections' based on month. The "Columns" are for various products - which are dynamic.

So for a forecast for November of 2012 I'm doing the following;

I'm dynamically creating a DataTable with columns for UserId, Name, 3MonthProjection. Then adding a column for each Product also (via a loop). So if next month - a new product is available - it will be added to the list.

Then I'm populating the datatable with respective values for each sales rep. If the sales rep has no forecast created for the month/year or product - just showing zero's.

Now - because my columns are dynamic - I can't think of a way to "beautifully" render the grid except w/ AutoGenerateColumns=true

To cut down on un-important columns - I'm making the Name column including an edit link which formats a link w/ values of UserId, ForecastId (may be null), Month, Year. This link is only be generated if the user has edit permissions (Admin can edit all - user can edit their own)

The column data is displaying:

Dennis Welker <a href="javascript:dnnModal.show('http://mysite.com/SalesReps/tabid/83/ctl/forecast/mid/425/uid/8/fid/601/mo/9/yr/2012/Default.aspx?popUp=true',/*showReturn*/false,550,950,true,'')">Edit</a>

Instead of rendering it like: Dennis Welker Edit
(where Edit is a link)

If I haven't confused you - do you have any idea on how to get the data to display as a link? Thanks!

You can use Server.HtmlEncode method in order to encode your link

Link : http://msdn.microsoft.com/fr-fr/library/vstudio/w3te6wfz.aspx

Nota : You apply this function on your datas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM