Question

In my code i create a HyperLinkField object. Depending on a database field value, i want to set the NavigateUrl property. This is my problem, i don't know how.

With:

objHF.DataNavigateUrlFields = new[] { "id", "Stype" };

i get my database field. Now i want to check the Stype value. Depeding on this value i want to set the page where to navigate to. How can i do this??

At the end i set my datasource to the gridview and after that i call the bind() method.

I hope someone can help me out

Was it helpful?

Solution

Make the HyperLinkField a TemplateField, and set the NavigateUrl of the resulting HyperLink (in markup) to something like

<%# myUrlFunction(Eval("id"), Eval("stype")) %>

Next create a corresponding function in the .cs file:

private string myUrlFunction(object id, object stype)
{
    return "mypagename.aspx?whatever=" + id.ToString() + 
        "&youwanttodo=" + stype.ToString();
}

OTHER TIPS

try this way

<%# this.myUrlFunction(Eval("id"), Eval("stype")) %>

this is worked

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top