DataList裡套DataGrid,DataBind嘛搞?

來源:互聯網
上載者:User
datagrid

這是九婆婆給的方法:
完整的例子:
◆MyGrid.ascx:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="MyGrid.ascx.cs" Inherits="XsStudio.test.MyGrid" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:DataGrid id="DataGrid1" runat="server" ShowHeader="False" AllowPaging="True" PageSize="3"></asp:DataGrid>

◆MyGrid.ascx.cs
namespace test
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
///  MyGrid 的摘要說明。
/// </summary>
public class MyGrid : System.Web.UI.UserControl
{
  protected System.Web.UI.WebControls.DataGrid DataGrid1;

  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此處放置使用者代碼以初始化頁面
  }

  public void loaddata(string id)
  {
   DataTable dt = new DataTable();
   dt.Columns.Add("SN");
   dt.Columns[0].AutoIncrementSeed=1;
   dt.Columns[0].AutoIncrement = true;
   dt.Columns.Add("AAA");
   dt.Columns.Add("BBB");
   dt.Columns.Add("CCC");
   dt.Rows.Add(new string[]{"1",id,"435689",System.DateTime.Now.ToString()});
   dt.Rows.Add(new string[]{"2",id,"34535",System.DateTime.Now.ToString()});
   dt.Rows.Add(new string[]{"3",id,"4456",System.DateTime.Now.ToString()});
   dt.Rows.Add(new string[]{"4",id,"64563",System.DateTime.Now.ToString()});
   dt.Rows.Add(new string[]{"5",id,"84535",System.DateTime.Now.ToString()});
   this.DataGrid1.DataSource = dt;
   this.DataGrid1.DataBind();
   ViewState[this.ClientID+"_id"] = id;
  }

  private void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
  {
   this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
   loaddata(ViewState[this.ClientID+"_id"].ToString());
  }

  #region Web Form設計器產生的程式碼
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 該調用是 ASP.NET Web Form設計器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
 
  /// <summary>
  ///  設計器支援所需的方法 - 不要使用代碼編輯器
  ///  修改此方法的內容。
  /// </summary>
  private void InitializeComponent()
  {
   this.Load += new System.EventHandler(this.Page_Load);
   this.DataGrid1.PageIndexChanged+=new DataGridPageChangedEventHandler(DataGrid1_PageIndexChanged);
  }
  #endregion


}
}

◆webform1.aspx:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="XsStudio.test.WebForm1" validateRequest=false%>
<%@ Register TagPrefix="uc1" TagName="MyGrid" Src="MyGrid.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
  <title>WebForm1</title>
  <META http-equiv="Content-Type" content="text/html; charset=gb2312">
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="C#" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body bgColor="#cccccc" MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <asp:DataList id="DataList1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server">
    <ItemTemplate>
     <asp:TextBox id="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ID") %>'></asp:TextBox>
     <asp:TextBox id="Textbox2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "smallPicPath") %>'></asp:TextBox>
     <uc1:MyGrid id="MyGrid1" runat="server"></uc1:MyGrid><br/>
    </ItemTemplate>
   </asp:DataList>
  </form>
  <script language="javascript">
 
  </script>
</body>
</HTML>

◆webform1.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;
u



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。