我把代码给你们看一下,然后你们帮我改下,我很急的.我把我全部的分都给出来了.
希望大家帮帮忙.我想实现里面按钮的事件.
using System;
using System.Data;
using System.Data.OleDb;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace mianshi
{
/// <summary>
/// cao 的摘要说明。
/// </summary>
public class cao:WebControl
{

private DataSet ds;
protected TextBox txt1,txt2,txt3,txt4,txt5,txt6;
protected Button bt,btn2,btn3,btn4,btn5,btn6,btn7,btn8;
public cao()
{
this.Width=new Unit(100,UnitType.Percentage);
this.Height=new Unit(50,UnitType.Percentage);
this.CssClass="sub1";
}
#region Web 窗体设计器生成的代码

protected override void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit (e);
} /// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
             this.bt.Click+=new EventHandler(bt_Click);
}
#endregion

protected override void CreateChildControls()
{
databind();
DataView dv=(DataView)Context.Session["key"];
Table tb=new Table();
tb.Width=new Unit(100,UnitType.Percentage);
tb.Height=new Unit(50,UnitType.Percentage);

TableRow tr;
TableCell tc;

tc=new TableCell();
tc.Text="工作地址:";
tc.CssClass="tx";
tr.Cells.Add(tc);
tb.Rows.Add(tr);
////////////////////
txt4=new TextBox();
tc=new TableCell();
tc.Controls.Add(txt4);
tr.Cells.Add(tc);
tb.Rows.Add(tr);
tr=new TableRow();
bt=new Button();
bt.Text="第一条";
tc=new TableCell();
tc.CssClass="bt";
tc.Controls.Add(bt);
tr.Cells.Add(tc);
tb.Rows.Add(tr);
////////////////////
btn2=new Button();
btn2.Text="上一条";
tc=new TableCell();
tc.CssClass="bt";
tc.Controls.Add(btn2);
tr.Cells.Add(tc);
tb.Rows.Add(tr);
/////////////////////////////////////////

btn3=new Button();
btn3.Text="下一条";
tc=new TableCell();
tc.CssClass="bt";
tc.Controls.Add(btn3);
tr.Cells.Add(tc);
tb.Rows.Add(tr);
////////////////////////////////

btn4=new Button();
btn4.Text="末 条";
tc=new TableCell();
tc.CssClass="bt";
tc.Controls.Add(btn4);
tr.Cells.Add(tc);
tb.Rows.Add(tr);
////////////////////////////////////////////////
this.Controls.Add(tb);

txt1.DataBinding+=new EventHandler(txt1_DataBinding);
base.CreateChildControls ();
}
public void databind()
{
ds=new DataSet();
string str="select * from emp2 ";
string str1="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Context.Server.MapPath("~//mydb//sujun.mdb") + ";User Id=admin;Password=;";
OleDbConnection con=new OleDbConnection(str1);
con.Open();
OleDbDataAdapter da=new OleDbDataAdapter(str,con);
da.Fill(ds,"tt");
DataView dv=ds.Tables["tt"].DefaultView;
Context.Session["key"]=dv;  
con.Close();
}
private void bt_Click(object sender, EventArgs e)
{

Context.Response.Write("<script defer>alert('asdfasf');</script>");
} private void txt1_DataBinding(object sender, EventArgs e)
{
DataView dv=(DataView)Context.Session["key"]; txt1.Text=dv[0]["name"].ToString();
}
}
}

解决方案 »

  1.   

    需要声明
    public event EventHandler ButtonClick; 并实现:IPostBackEventHandler接口,
      

  2.   

    1、用EventHandler做为事件委托(如果事件有数据则需要继承一个EventAgrs的类)
    2、在控件里面使用event定义一个事件(使用public公开)
    3、在控件里面使用一个虚拟的方法调用事件委托(通常是一个OnEventName的函数)
      

  3.   

    你可以参考我的分页控件AspNetPager的源码:http://www.webdiyer.com