views:

3274

answers:

2

Hi,

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

A: 

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();
}
devio
A: 

I don't get it work.

I have the following in my aspx file:

<asp:HyperLink ID="myHyperlink" CssClass="TitelCel" runat="server"  NavigateUrl='<%# myUrlFunction(Eval("id"), Eval("stype"))%>' Text='<%# Bind("Naam") %>'></asp:HyperLink>

With this i get the error "CS0103: The name 'myUrlFunction' does not exist in the current context"

Martijn
NavigateUrl='<%# myUrlFunction(Eval("id"), Eval("stype"))%>'
devio
did you write the function in .cs ?
devio