c# - ASP.Net binding attributes of a custom control's inner property -


i have created usercontrol inner property called "actions", list of "action" objects. code looks this:

[parsechildren(true)] public class mylink : usercontrol {     readonly list<action> _actions = new list<action>();      [persistencemode(persistencemode.innerproperty)]     public list<action> actions     {         { return _actions; }     }      public string text { get;set; }     public string url { get;set; }     public string menuname { get; set; }      protected override void render(htmltextwriter writer)     {         //build link         stringbuilder sb = new stringbuilder();         sb.append(@"             <table class=""mylink"">                 <tr>                     <td class=""mylinkleft""><a href=" + url + @">" + text + @"</a></td>                     <td class=""mylinkright " + menuname + @"_trigger"">&nbsp;</td>                 </tr>             </table>         ");          //build actions         sb.append("<ul id=\"" + menuname + "_actions\" class=\"contextmenu\">");          foreach (action action in _actions)         {             sb.append("<li class=\"" + action.cssclass + "\"><a href=\"#" + action.url + "\">" + action.text + "</a></li>");         }          sb.append("</ul>");          writer.write(sb.tostring());     } }  public class action : usercontrol {     public string url { get; set; }     public string text { get; set; }     public string imageurl { get; set; }     public string cssclass { get; set; } } 

if put code in aspx inside datarepeater, works fine:

<uc1:mylink runat="server" url="/" text='<%#databinder.eval(container.dataitem,"text") %>' menuname="contextmenu" id="contextmenu">     <actions>         <uc1:action runat="server" url="http://mysite.com" text="myurl"  />         <uc1:action runat="server" url="http://google.com" text="google" />     </actions> </uc1:mylink> 

however, if try bind data attributes of action elements so:

<uc1:mylink runat="server" url="/" text='<%#databinder.eval(container.dataitem,"text") %>' menuname="contextmenu" id="contextmenu">     <actions>         <uc1:action runat="server" url='<%#databinder.eval(((repeateritem)container.parent).dataitem,"url") %>' text="myurl"  />         <uc1:action runat="server" url="http://google.com" text="google" />     </actions> </uc1:mylink> 

i merely actual text "<%#databinder.eval(((repeateritem)container.parent).dataitem,"url") %>" assigned url property, , not evaluated server expression expected.

i've googled hours cannot seem find else trying this. ideas why isn't working , how around it?

thanks, bjoern

you set datarepeater.datasource in aspx collection or list static or database ...

instead of using datarepeater try make loop inside list re must create , create new dynamic action , in page_load or page_init

action a; foreach(object x in objects) {    a= new action();    a.url = ... ;    a.text = ... ;    mylink.actions.add(a); } 

regards


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -