添加一个DataList
ID为DataList1
再在DataList1项模版里添加一个Label
ID为Label1
请问如何用编程方式更改这个Label1的Text属性呢?
this.Label1.Text="你好";
这样是不行的哟

解决方案 »

  1.   

    既然叫做List必然是一个集合,DataList的模板代表了集合的每一个ListItem, 所以Label.Text赋值当然不能简单的Lable1.Text="你好"。最简单的方法就是创建一个集合对象,比如说DataTable,然后把DataTable作为ListView的数据源(WebForm)。除了用DataTable之外,你还可以使用其他集合如ArrayList, List<T>(2.0)等。
      

  2.   

    添加DataList1_ItemDataBound事件。
    Label label1 = (Label)e.Item.FindControl("Label1");
    label1.Text = "你好";Good Luck:)
      

  3.   

    http://chs.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/customize/datalist8.src
      

  4.   

    非常感谢各位
    问题已经得到解决
    我之前用DataList1.FindControl()方法
    但是根本不行