日期:2014-05-19  浏览次数:20958 次

超高分求解,一个非常实用,但至今论坛中无人解决的问题,如果能解决肯定当之无愧的成为中国最熟悉DataList的人(在后台中自动生成DataList,
一个非常实用,但至今论坛中无人解决的问题,如果能解决肯定当之无愧的成为中国最熟悉DataList的人(在后台中自动生成DataList,并用后台进行绑定,注意不是前台绑定),已经有好多贴,可是都没解决,我这里再加100分求解

相关贴子有:
http://community.csdn.net/Expert/topic/5559/5559722.xml?temp=.7824823
http://community.csdn.net/Expert/topic/5558/5558033.xml?temp=.7784998
http://community.csdn.net/Expert/topic/5552/5552781.xml?temp=.7758142

------解决方案--------------------
看着标题很长就进来了.
------解决方案--------------------
一个个的看看链接,不会再悄悄地走开...
------解决方案--------------------
回家先研究一下,完了再来告诉LZ!
------解决方案--------------------
慢慢看再说
------解决方案--------------------
MARK LOOK
------解决方案--------------------
后台绑定一般通过ItemDataBound来处理
还没有见过这样绑定的
------解决方案--------------------
你可以在后台New一个DataList,并绑定数据,但模板必须事先建好!
------解决方案--------------------
先进来
------解决方案--------------------
看看这个能不能满足你的基本要求

//aspx
<%@ Page Language= "C# " AutoEventWireup= "true " CodeBehind= "Default.aspx.cs " Inherits= "Default " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "Button " />
</div>
</form>
</body>
</html>

//aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Default : System.Web.UI.Page
{
private DataView GetAuthors()
{
SqlConnection cn = new SqlConnection(@ "server=.\SQLExpress;uid=sa;pwd=password;database=pubs ");
SqlDataAdapter da = new SqlDataAdapter( "select * from authors ", cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
cn.Close();
return ds.Tables[0].DefaultView;
}

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
DataList d = new DataList();
d.ID = "dlstTest ";

d.ItemTemplate = new MyColumn( "h1 ", 200);
d.ItemDataBound +=new DataListItemEventHandler(d_ItemDataBound);
d.DataSource = this.GetAuthors();
d.DataBind();
this.form1.Controls.Add(d);
}

private void d_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)