请教:怎样设置动态添加的用户控件的属性?原来的具体问题比较繁杂,简化如下:
动态添加了用户控件:……
Dim i As Integer
For i = 0 To 5
    Dim myUserControl As Control
    myUserControl = Page.LoadControl("Control_Template.ascx")
    PlaceHolder1.Controls.Add(myUserControl)Next
……
<asp:PlaceHolder id="PlaceHolder1" Runat="server"></asp:PlaceHolder>
……
Control_Template.ascx如下:……
<table>
    <tr>
        <TD>题目序号:</TD>
        <TD><asp:Label id="QuestionID" runat="server">1</asp:Label></TD>
    </tr>
    <tr>
        <TD>题干内容:</TD>
        <TD><asp:TextBox id="QuestionName" runat="server" TextMode="MultiLine" Width="279px" Height="117px"></asp:TextBox></TD>
    </tr>
<table>
……
现在想分别设置每一个添加的用户控件的题目序号QuestionID和题干内容QuestionName的Text属性。请教各位GGJJ&DDMM,该怎样才能实现这一功能呢?
谢谢!万分感激!

解决方案 »

  1.   

    control.Attributes.Add("shuxing","value")
      

  2.   

    你可以在Control_Template.ascx.cs内加一个属性 比如叫AAA    Dim myUserControl As UserControl
        myUserControl = Page.LoadControl("Control_Template.ascx")
        myUserControl.AAA = "adfadf";
        PlaceHolder1.Controls.Add(myUserControl)
      

  3.   

    QuickStarts真是一个好东西居然从里面找到了一种解决的办法,虽然不简洁,如下:  ^_^        For i = 0 To 5
                Dim myUserControl As Control
                Dim Question As Label            myUserControl = Page.LoadControl("Control_Template.ascx")
                Question = myUserControl.FindControl("QuestionID")
                Question.Text = "第" & i & "题"            PlaceHolder1.Controls.Add(myUserControl)
            Next