DataList里套DataGrid DataBind

2016-01-29 19:54 18 1 收藏

DataList里套DataGrid DataBind,DataList里套DataGrid,DataBind

【 tulaoshi.com - ASP 】

完整的例子:
◆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;

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/asp/)

/// <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 窗体设计器生成的代码
  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);
   this.DataGrid1.PageIndexChanged+=new DataGridPageChangedEventHandler(DataGrid1_PageIndexChanged);
  }
  #endregion

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/asp/)


}
}

◆webform1.aspx:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="XsStudio.test.WebForm1" validateRequest=false%
<%@ Register TagPrefix="uc1" TagName="MyGrid" src="http://img.jcwcn.com/attachment/portal" %
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
<HTML
<HEAD
  <titleWebForm1</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(

来源:https://www.tulaoshi.com/n/20160129/1510351.html

延伸阅读
使用 DataGrid 控件 DataGrid 控件是一种类似于电子数据表的绑定控件,可以显示一系列行和列来表示 Recordset 对象的记录和字段。可以使用 DataGrid 来创建一个允许最终用户阅读和写入到绝大多数数据库的应用程序。DataGrid 控件可以在设计时快速进行配置,只需少量代码或无需代码。当在设计时设置了DataGrid 控件的 DataSource 属性...
1、选择要显示的列: 在默认的情况下,我们在DataGrid中显示的列就是我们在执行Sql查询语句的时候查询出来的列,什么意思呢?如果我们用Select * from myTable,那么,将会显示所有的列,如果,我们用Select field1,field2 from mytable那么就只显示两个列。所以,在Datagrid中要选择你要显示的列,最简单的方法不是修改属性来完成,而是通过修...
使用列 通过更改DataSource属性,可以动态地更改在DataGrid控件中显示的数据。例如,可以显示同一个数据库的不同表。如果这样做,则DataGrid控件将只根据默认的属性显示数据。 添加、删除或隐藏列 通过使用Columns集合和Column对象的属性和方法,可以在程序中添加、删除或隐藏列。 添加和删除一列 要在运...
using System;using System.Drawing;using System.Collections;using System.Windows.Forms;namespace cSharpDataGrid{ public class MyDataGrid : System.Windows.Forms.DataGrid { private ArrayList m=new ArrayList(); Array MultiSelectedIndex { get { return this.m.ToArray(typeof (int)); } } protected override void OnMouseDown(Sy...
创建一个简单的DataCombo应用程序 下面的示例使用DataCombo控件为Northwind.mdb示例数据库的Titles表创建一个数据输入界面。这个输入界面使用户可以输入新的产品,并通过提供一个包括所有供应商名称的查找表将这些新产品指定到已有的供应商。当用户在输入窗体中要输入供应商字段的值时,他们可以从一个列表框中选择一个供应商。当他...

经验教程

855

收藏

35
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部