Discussion Locked

ASP.NET Datagrid Question

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a question about the HyperlinkColumn template item which can be used in ASP.NET's DataGrid object. Basically, I am trying to read e-mail addresses from a database table and then display them on a web page datagrid, with the e-mail addresses dynaminally linked to the e-mail address field using the mailto: tag. However, when I try to do this by concatenating the DataNavigateUrlFormatString property and the e-mail field object, I get a server error message that says something like "Databinding is not a property of DataGrid" (HyperlinkColumns doesn't like the <%# %> databinding syntax). Also I was hoping someone could let me know what I am doing wrong here and how I can achieve the desired result. Thanks

6 replies

by medievaldude

Something I have tried with data grids (and I don't know if this will work in your situation, but what they hey)...
When I call the field from the database, I would embed the anchor tag with it so that the datagrid interprets it as HTML. Example:SELECT '' + MyURLField + '""' AS MyURLField FROM MyTable
Or in your case:
SELECT '' + MyEmailAddressField + '""' AS MyEmailAddressField FROM MyTable

by galahad04

Thanks for your suggestion. Unfortunately, this approach did not seem to work for me when I using it in my stored procedure.

by galahad04

Quick correction -- the part where I wrote "I get a server error message that says something like Databinding is not a property of DataGrid" should be listed as "I get a server error message that says something like Databinding is not a property of HyperlinkColumn".

by crispy1

I have never tried this, but I have a datagrid that navigates to a different page based on an id, when i change the link to the mailto: it opens my email composer and fills the to field with the id, so i am positive this should at least point you inthe right direction.
Good luck.

by galahad04

This solved the problem perfectly! Plus very simple and elegant -- thanks a bunch! If you don't mind though, I do have a quick follow-up question: what exactly does the {0} syntax in the code represent? I tried researching it in the Visual Studio .NET help documentation, but could not find anything that explained how exactly this syntax works and what it represents. The senior programmers at work couldn't make any sense of it either. If you could please e-mail me at caramon@peoplepc.com, I would deeply appreciate it. Thanks again

This discussion is closed to new replies.