如题...

解决方案 »

  1.   

    在DataList的Created事件中:
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlertnItem)
    {
       TextBox txtBox = new TextBox();
       e.Items[0].Controls.Add(txtBox);      
    }
    //Sorry,上述代码有些关键字突然想不起来
    //记不清了,大概就这样
      

  2.   

    <script>sub page_load()... ...   数据库连接代码,,,执行sql语句代码等do while dr.read()dim mybutton as new button()
    placeholder1.controls.add(mybutton)
      
    end whileend sub</script>
    <asp:datalist id=datalist1 runat=server>
    <itemtemplate>
    <asp:placeholder id = placehorder1 runat=server></asp:placeholder>
    </itemtemplate>
    </asp:datalist>
    添加的控件也可以是自定义控件,,而且可以帮定属性
    do while dr.read()
    dim myuc as new myuc_ascx()
    placeholder1.controls.add(myuc)
    myuc.username=dr("user")       
    end while这里假如myuc控件有一个username的属性,,,并且将数据表中的user字段的值帮定到了username属性上
      

  3.   

    但是PlaceHolder是在模板列中的,我在写程序的时候如何才能取得这个控件啊?像你那样直接引用是不行的
      

  4.   

    Label label=new Label();
    label.Text+="<img src='"+MapPath("01s.jpg")+"'>";
    this.DataList1.Items[0].Controls.Add(label);