I'm trying to dynamically create a grid view in C#, the grid will have two columns, one of which is a hyperlink field.
Now i've noticed when creating the grid view statically in aspx, the DataNavigateUrlFields property accepts a single string as it's value (the field in the data source with the URL in).
When creating it in code, the very same property is a string array, rather than a single string, and is expecting multiple fields which combine together to make the URL (if I've understood MSDN correctly), but what if I just want a single field for the URL?
Why does aspx let me do this, but the C# not?
Here's my code:
Name.HeaderText = "Exercise";
Name.DataField = "Name";
Link.HeaderText = "More Info";
Link.DataTextField = "Link";
Link.DataNavigateUrlFields = "Link";
The code above does NOT compile, I got the following error:
Error 2 Cannot implicitly convert type 'string' to 'string'
This is regarding the last line.
Here is the aspx code, which it's fine with:
<asp:HyperLinkField HeaderText="More Info" DataTextField="Link" DataNavigateUrlFields="Link"
Does anyone know how I can dynamically create a hypertext field for a grid view, where it only takes a signle field from the data source as the URL?
Thanks for your help,