获取DataList和Repeater里的控件

后台代码:

  
    
       // foreach (DataListItem item in DataList1.Items)
// {
// if (item.FindControl("lbl") != null)
// {
// TextBox1.Text = ((Label)item.FindControl("lbl")).Text;
// }
// else
// {
// Response.Write("w ca");
// }
// }
foreach (RepeaterItem item in Repeater1.Items)
{
if (item.FindControl( " lbl " ) != null )
{
TextBox1.Text
= ((Label)item.FindControl( " lbl " )).Text;
}
else
{
Response.Write(
" w ca " );
}
}

页面控件:

  
    
  < asp:DataList ID = " DataList1 " runat = " server " >
< ItemTemplate >
< asp:Label ID = " lbl " runat = " server " Text = " Label " />
</ ItemTemplate >
</ asp:DataList >
< asp:Repeater ID = " Repeater1 " runat = " server " >
< ItemTemplate >
< asp:Label ID = " lbl " runat = " server " Text = " Label " />
</ ItemTemplate >
</ asp:Repeater >
  
< asp:TextBox ID = " TextBox1 " runat = " server " ></ asp:TextBox >

你可能感兴趣的:(datalist)