DataList里套DataGrid,DataBind嘛搞?

作者:袖梨 2022-06-30
这是九婆婆给的方法:
完整的例子:
◆MyGrid.ascx:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="MyGrid.ascx.cs" Inherits="XsStudio.test.MyGrid" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

◆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;
///
///  MyGrid 的摘要说明。
///

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;

相关文章

精彩推荐