DATALIST 如何给headertemplate内的label1.text赋值? DataList绑定的时候(ItemDataBound )循环DataListItem,用((Label)FindControl("Label1")).Text = 你需要的值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //In page<asp:Label id="" Text= '<%labText%>' runat="server"/>//in Codeprotected string labText;labText= "..."; forech(DataListItem Item in DataList1.Controls[0].Controls){ if(Item.Type==ListItemType.Header) { Label Label1=(Label1)Item.FindControl("Label1"); }}J老师也搞web开发了? 如果用 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 }} 解决了.多谢! bitsbird(一瓢): 刚学,不会,以后多指点!! OracleDataAdapter的奇怪问题 各位大哥,有个基础问题,ASP.NET版暂停了,来这里问. c# hashtable的VALUES排序问题 winfroms问题,当前界面有几个ComBoBox绑定是相同的数据源 如何按快捷弹出窗体? 江湖救急_关于C#中使用Excel2003操作HyperLink的问题(急) 关于FreeTextBox 1.6 SQLServer的连接经常被关闭,怎么回事呢? dataSet 可以使用临时表(#Table)吗?我好像无法用 vs.net开发的程序如何在wince平台运行。 请教高手,怎样实现这个功能 网络搜索问题。,,高手进!!!!!!!!!!
<asp:Label id="" Text= '<%labText%>' runat="server"/>//in Code
protected string labText;
labText= "...";
{
if(Item.Type==ListItemType.Header)
{
Label Label1=(Label1)Item.FindControl("Label1");
}
}
J老师也搞web开发了?
可以把要绑定的内容暴露为 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
}
}