我想写一个控件
<LvBBS:GroupBox Runat="server" ID="Gru">
<Text>123</Text>   <--
<Content>46579</Content><--这两个属性代码要怎么写,
</LvBBS:GroupBox>怎么做才像Repeater那样Itemplate一样这是我写的
namespace Skin.WebComponents
{
/// <summary>
/// GroupBox 的摘要说明。
/// </summary>
[
DefaultProperty("GroupBox"),
ToolboxData("<{0}:GroupBox runat=server></{0}:GroupBox>")
] public class GroupBox:Control,INamingContainer
{

private ITemplate text;
private ITemplate content;
public GroupBox(){}
public ITemplate Text
{
set{text=value;}
get{return text;}
}
public ITemplate Content
{
set{content=value;}
get{return content;}
} protected override void CreateChildControls() 
{

this.Controls.Add(new LiteralControl(WriteHTML()));
} private string WriteHTML()
{
StringBuilder HTML = new StringBuilder();
HTML.Append(@"
<table cellspacing='0' cellpadding='0' width='100%'>
<tr>
<td width='3'>
<img height='14' src='images/tbl_topleft.gif' width='3'></td>
<td class='HeaderTxt' align='left' background='images/tbl_top.gif'>
<img height='3' src='images/tbl_spacer.gif' width='1'>
<font class='ForumBody1RoundedTableHeader'>
&nbsp;"+this.Text+@" </font>
</td>
<td width='3'>
<img height='14' src='images/tbl_topright.gif' width='3'></td>
</tr>
<tr>
<td width='3' background='images/tbl_left.gif'>
<img height='1' src width='3'></td>
<td class='smalltxt' valign='top'>
<table  cellspacing='1' cellpadding='9' width='100%'>
<tr>
<td class='SmallTxt' width='100%'>
"+this.Content+@"
</td>
</tr>
</table>
</td>
<td width='3' background='images/tbl_right.gif'>
<img height='1' src='images/tbl_spacer.gif' width='3'></td>
</tr>
<tr>
<td width='3'>
<img height='3' src='images/tbl_bottomleft.gif' width='3'></td>
<td background='images/tbl_bottom.gif'>
<img height='3' src='images/tbl_spacer.gif' width='1'></td>
<td width='3'>
<img height='3' src='images/tbl_bottomright.gif' width='3'></td>
</tr>
</table>
");
return HTML.ToString();
} }
}运行之后的HTML成了这样子,
<Text>123</Text><---- 这两个没指行晕
<Content>46579</Content><----
         <table cellspacing='0' cellpadding='0' width='100%'>
<tr>
<td width='3'>
<img height='14' src='images/tbl_topleft.gif' width='3'></td>
<td class='HeaderTxt' align='left' background='images/tbl_top.gif'>
<img height='3' src='images/tbl_spacer.gif' width='1'>
<font class='ForumBody1RoundedTableHeader'>
&nbsp; </font>
</td>
<td width='3'>
<img height='14' src='images/tbl_topright.gif' width='3'></td>
</tr>
<tr>
<td width='3' background='images/tbl_left.gif'>
<img height='1' src width='3'></td>
<td class='smalltxt' valign='top'>
<table  cellspacing='1' cellpadding='9' width='100%'>
<tr>
<td class='SmallTxt' width='100%'>

</td>
</tr>
</table>
</td>
<td width='3' background='images/tbl_right.gif'>
<img height='1' src='images/tbl_spacer.gif' width='3'></td>
</tr>
<tr>
<td width='3'>
<img height='3' src='images/tbl_bottomleft.gif' width='3'></td>
<td background='images/tbl_bottom.gif'>
<img height='3' src='images/tbl_spacer.gif' width='1'></td>
<td width='3'>
<img height='3' src='images/tbl_bottomright.gif' width='3'></td>
</tr>
</table>

解决方案 »

  1.   

    你要是要调用用户控件的属性的话,,,可以这样设置
    <LvBBS:GroupBox Runat="server" ID="Gru" text="xxxxx">
    </LvBBS:GroupBox>
    也可以在事件中处理gru.text="xxxx"
    但是如果象你说的那种情况,,就不是属性的问题了,,,那个叫做模板 ,,,,需要模板接口的支持,,,,Itemplate这个好象就是接口名
      

  2.   

    see the following article on how to develop a templated control
    http://chs.gotdotnet.com/quickstart/aspplus/doc/webctrlauthoring.aspx