Welcome Guest Search | Active Topics | Sign In | Register

Hyperlink in datagrid? Options
HT
Posted: Friday, March 21, 2008 5:25:41 PM
Rank: Advanced Member
Groups: Member

Joined: 3/18/2008
Posts: 41
How can I populate a datagrid column with a hyperlink with a parameter from the database in the URL?
Something like this:
Code: HTML/ASPX
<a href="mypage.aspx?id={0}">{1}</a>
eo_support
Posted: Friday, March 21, 2008 5:54:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You won't be able to do exactly that. With each column you only got one DataField, which means you only get one data variable. Usually you would give this to the link text. So in your case you should use a ButtonColumn, with its type set to LinkButton and leave its Text field blank, but set its DataField property. This DataField will be used to populate the link text.

The second argument, which would be your href id query string argument, is supplied through the Grid's KeyField property. By setting the Grid's KeyField property, you would carry the key field value down to the client side, which can be retrieved later by JavaScript call.

Once those are done, you can handle the Grid's ClientSideOnItemCommand, within that event handler you can then do:

Code: JavaScript
function itemcommand_handler(
    grid, itemIndex, colIndex, commandName)
{
   window.open(
        "mypage.aspx?id=" + grid.getItem(itemIndex).getKey(), 
        "_self");
}


Hope this helps.

Thanks

HT
Posted: Friday, March 21, 2008 6:23:19 PM
Rank: Advanced Member
Groups: Member

Joined: 3/18/2008
Posts: 41
Thanks!! It works :D

Please note that I had to convert the SQL Servers uniqueidenfier datatype to nvarchar in the SQL query to make it work. Otherwise, I got "undefined" in the parameter value in the javascript.

SELECT Convert(nvarchar(200), Id) as id, .....

Regards,
HT
eo_support
Posted: Friday, March 21, 2008 6:56:47 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Ah. Thanks for letting us know. We will look into that and see what we can find.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.