C # Changing dynamically NavigateUrl HyperLinkField

In my code, I am creating a HyperLinkField object. Depending on the value of the database field, I want to set the NavigateUrl property. This is my problem, I don't know how to do it.

FROM

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

      

I am getting my database field. Now I want to check the Stype value. Based on this value, I want to set the page to go to. How can i do this?

In the end, I set my datasource to the gridview and after that I call the bind () method.

Hope someone can help me.

+1


source to share


2 answers


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

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

      



Then create the appropriate function in the .cs file:

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

      

+1


source


try this way

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

      



it works

+1


source







All Articles