views:

28

answers:

1

I am storing small webpages in html format in a varchar(max) column in MS SQL server 2008. Now I want the gridview to show the column as a button/hyperlink such that when I click it, I will be redirected to a new webpage which will render the html in the table corresponding to that row.

I tried using the buttonfield control but there doesn't seem to be any way I can access the datafield and underlying html in that case. Any ideas, peeps?

+1  A: 

Make the link to point to somepage.aspx?id=xxx, where xxx is id of the row that contains the required html. In somepage.aspx in Page_Load event read teh html from sql server and write it to the client. Something like this:

        <asp:TemplateField HeaderText="">
            <ItemTemplate>
                <a href="mypage.aspx?id=<%# Eval("ID") %>">View</a>
            </ItemTemplate>
        </asp:TemplateField>
Alex Reitbort
But then, how do I get the id to which I have to bind? I have an ID column in sql, but I don't want to show it on the gridview. Is there a way I can use that Id column without binding it to sql?
Raze2dust
You do not have to show it in the grid, you just have to generate the link using this column
Alex Reitbort
using eval()? or is there another way to do this?
Raze2dust
yes, see update to my answer.
Alex Reitbort
yea.. this could work, i'll try it. Doesn't eval() slow down the page though?
Raze2dust
it works, thanks :)though I have a feeling it is a dirty way of doing it. Let me know if you come across some other way too.. cheers
Raze2dust
This is not a dirty way of doing this. This is the standard way of implementing this scenario.
TheGeekYouNeed