Hello all. I have a user control class like this:
///MyUserControl.ascx.cs
///.......
public partial class MyUserControl
: UserControl
{
//....
public List<HyperLink> Items
{
get
{
return _Items;
}
}
public string RenderControl(WebControl control)
{
StringBuilder sb = new StringBuilder();
using(StringWriter stringWriter = new StringWriter(sb))
{
HtmlTextWriter writer = new HtmlTextWriter(stringWriter);
control.RenderControl(writer);
}
return sb.ToString();
}
//....
}
I want to add all Items
to render tree in ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyUserControl.ascx.cs" Inherits="MyUserControl" %>
<%foreach (var item in Items){%>
<div>
<%=RenderControl(item)%>
</div>
<%}%>
But it's ugly solution. Does anybody know better solution?