DataList绑定的时候(ItemDataBound )
循环DataListItem,用((Label)FindControl("Label1")).Text = 你需要的值

解决方案 »

  1.   

    //In page
    <asp:Label id="" Text= '<%labText%>' runat="server"/>//in Code
    protected string labText;
    labText= "...";
      

  2.   

    forech(DataListItem Item in DataList1.Controls[0].Controls)
    {
      if(Item.Type==ListItemType.Header)
        {
          Label Label1=(Label1)Item.FindControl("Label1");
        }
    }
    J老师也搞web开发了?
      

  3.   

    如果用 OO 的写法,你可以用数据绑定语法  <%#    %>
    可以把要绑定的内容暴露为 property 或者 public method.例如:WebForm6.aspx
    --------------------<%@ Page language="c#" Codebehind="WebForm6.aspx.cs" AutoEventWireup="false" Inherits="MyPlayground.WebForm6" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm6</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <asp:DataList id="dl" runat="server" DataSource='<%# GetDataSource() %>'>
    <HeaderTemplate>
    <asp:Label ID="lbl1" Runat="server"><%# DataListLabel %></asp:Label>
    </HeaderTemplate>
    </asp:DataList>
    </form>
    </body>
    </HTML>----------- 后台代码 WebForm6.aspx.cs ---------------------------
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace MyPlayground
    {
    /// <summary>
    /// WebForm6 的摘要说明。
    /// </summary>
    public class WebForm6 : PageBase
    {
    protected System.Web.UI.WebControls.DataList dl;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    this.DataBind();
    } public string DataListLabel
    {
    get
    {
    return "DataList Header";
    }
    } public DataTable GetDataSource()
    {
    return SqlScope.ExecuteDataTable("select 1, 2, 3");
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }
      

  4.   

    解决了.多谢! bitsbird(一瓢): 刚学,不会,以后多指点!!