答案:这是九婆婆给的方法:
完整的例子:
◆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 窗体设计器生成的代码
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
}
}◆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;
using Microsoft.Web.UI.WebControls;
using System.Data.OleDb;namespace XsStudio.test
{public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputText Text1;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
private void Page_Load(object sender, System.EventArgs e)
{// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
DataTable tb = new DataTable();
tb.Columns.Add("ID");
tb.Columns.Add("smallPicPath");
tb.Columns.Add("Remark");
tb.Columns.Add("Name");
tb.Columns.Add("SupportCount");
tb.Columns.Add("gdzs");
tb.Columns.Add("BrowserCount");
tb.Rows.Add(new string[]{"001","dwef321","weaf","ewfa","1","12","ewf"});
tb.Rows.Add(new string[]{"002","geawef","gaweg","43ga4","1","21","weg"});
tb.Rows.Add(new string[]{"003","berg","gaweg","43ga4","1","21","weg"});
tb.Rows.Add(new string[]{"004","54wh","gaweg","43ga4","1","21","weg"});
tb.Rows.Add(new string[]{"005","baerg","gaweg","43ga4","1","21","weg"});
DataList1.DataSource = tb;
DataList1.DataBind();
}
}
private void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if(e.Item.ItemIndex>-1)
{
string id = ((TextBox)e.Item.FindControl("TextBox1")).Text;
MyGrid tmpGrid = (MyGrid)e.Item.FindControl("MyGrid1");
tmpGrid.loaddata(id);
}
}#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.DataList1.ItemDataBound+=new DataListItemEventHandler(DataList1_ItemDataBound);
}
#endregion
}
}这个是我自己搞的:
在aspx文件里,是这样子套的<asp:datalist id="DataList1" runat="server" RepeatColumns="3" RepeatDirection="Horiz
- 更多asp疑问解答:
- asp正则过滤重复字符串的代码
- 用asp过滤全部html但保留br类似的符号
- 会asp,但感觉asp要过点,想学php。但我一般做的都是小公司的站,用access数
- PHP的空间可以用ASP的源代码吗?
- 以前做asp程序,现在应该怎样发展?是学.net还是php
- 以前做asp程序,现在应该怎样发展?是学.net还是php
- 想做一个市级的人才网acess,sql数据库,语言asp,jsp,php分别用哪种好
- jsp,asp,php 区别
- 我想找一个有比较多漏洞的网站的源码,比如可以asp,php注入等都可以。供学习研究用。请提供下载地址。。
- 现在候找人做个网站,用ASP,还是PHP语言去做好
- asp,php ,jsp,.net 对于做网站前台的重要吗?
- asp和php的区别是什么?
- 我是新手SEO菜鸟 请问wp dw php asp cms myspl dede 这些软件应该如何区分呀?
- 网页制作相关的三种语言:ASP JSP PHP那个好点,简单点?
- 网页制作相关的三种语言:ASP JSP PHP那个好点,简单点?