views:

561

answers:

1

Hello

Does anybody know if it is the way to set control's child attributes properties by inline code? I mean something like that

        <asp:MenuItem Text="text" NavigateUrl='<%# GetItemURL("val") %>' ></asp:MenuItem>

CodeBehind

        protected string GetItemURL(string tag)
        {
            if (string.IsNullOrEmpty(_pageUrl))
                _pageUrl = UrlManager.CastQueryString(Request.Url.ToString());            
            return string.Format("{0}?item={1}", _pageUrl, tag);
        }

Neither of approaches work, whatever you use <%#, <%= , Page.DataBind() etc, you get an obstacle.

It would be very ugly to set such properties in code-behind. I hope the some method allowing to set such properties in code render blocks is available

thanks in advance.

A: 

Your binding syntax is correct. You just need to make sure something is binding the parent of the <asp:MenuItem> control. You can even just run this.Page.Databind(); if there isn't a good databinding context already.

Mufasa