嵌套绑定DataList

  //动态绑定子控件

private void BindChild(DataList  childList, string productId)
{
           childList.DataSource = .... ;
           childList.DataBind();
}
.....

forearch(DataListItem item in myGrid.Items)
{
        DataList childList = (DataList)Item.FindControl("childLi");
        CheckBox chk = (CheckBox)Item.FindControl("chk");
        if(chk.Checked){
               BindChild(childList, chk.Value);
        }
}

//添加Dropdown的默认项
if(dropdown.Items.Count > 0)
{
        dropdown.Items.Clear();  
        ListItem li = new ListItem("text", "value");
        dropdown.Items.Add(li);
}

//为服务端控件添加客户端代码
textBox.Attributes.Add("onclick", "text_onClick()");

<script language="javascript">
    function text_onClick(){
            .....
    }
</script>


//JS可以直接调用服务端控件的值
<asp:textbox id="txt" runat="server"></asp:textbox>

js:  document.getElementById("txt").value   或 document.Forms[0].txt.value;


//在用户控件中再引入其他用户控件
1、建立一个所有用户控件集成的基类 UCBase
2、使用LoadControl("/uc/myUC.ascx")方法引入用户控件,该方法返回一个Control对象,所以必须进行转换。

Control  uc = (Control)LoadControl("~/uc/myuc.ascx");
((myuc)uc).Name = "my_usercontrol" ;    // (myuc)uc 的类型转换名称,必须与ascx文件的命名一样,而且大小写也要一样。
....
placeHolder.Controls.Add(uc);


//图片自动适应宽度
<img   src="http://images.cnblogs.com/mypic.jpg"   border="0"  onload='javascript:if(this.width>=200)this.width=200;'   alt=''   />

你可能感兴趣的:(嵌套绑定DataList)