各位大侠,我在aspx的页面中放了一个panel,在panel里我添加了一个DataList,而在DataList的项模板中加了一个html表格,在其中的一个单元格中放了一个label,通过数据绑定来显示数据库中的一个字段的值。
  我现在想直接从这个label得到它绑定的数据字段的值,不知道怎么做?
  请各们大侠帮帮忙,在线等,谢谢!!!

解决方案 »

  1.   

    lable 设一个 id ,根据 id 用 findcontrol 就行了吧
      

  2.   

    qi_jianzhou() ,可不可以说详细一点,最好能给一段代码,十分的感谢!!!
      

  3.   

    <asp:Lable ID="label1" ..... />
    {
      Label l = (LabeL)form1.FindControl("label1");
      string txt = l.Text;
    }
      

  4.   

    <asp:Lable ID="label1" ..... />
    -------------------------------
    if(e.Item.ItemType=ListItemType.Item || e.Item.ItemType=ListItemType.AlternatingItem)
    {  Label labName = (LabeL)form1.FindControl("label1");
      string txt = labName .Text;
    }
      

  5.   

    <asp:Lable ID="label1" ..... />
    -------------------------------
    protected System.Web.UI.WebControls.DataList DataList1;
    private string _str=String.Empty;
    public string Str
    {
       get{return _str;}
       set{_str=value;}
    }
    private GetLabelText()
    {
       foreach(DataListItem i in DataList1)
       {
          Label labName=(Label)i.FindControl("label1");
          Str=labName.Text;
       }
    }