那里有重写web服务器控件的例子!

解决方案 »

  1.   

    参考--
    http://www.codeproject.com/aspnet/masterdetailgrid.asp
      

  2.   

    参考微软的例子:http://msdn.microsoft.com/library/CHS/cpguide/html/cpconwalkthroughdevelopingsimplewebformscontrol.asphttp://www.ftponline.com/china/XmlFile.aspx?ID=316或者有本书《ASP.NET服务器控件与组件开发》
      

  3.   

    http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/cpconDevelopingWebFormsControls.asp
      

  4.   

    http://chs.gotdotnet.com/quickstart/aspplus/doc/webctrlauthoring.aspx
      

  5.   

    这个是我写的在原有的属性里加了
    分页功能
    排序功能
    序列号
    自己看吧
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Drawing;
    using System.ComponentModel;namespace Daniel.Web
    {
    public class DataGrid : System.Web.UI.WebControls.DataGrid
    {
    private string errMessage = "";
    public string ErrMessage{
    get{
    return this.errMessage;
    }
    }
    public DataGrid()
    {
    this.PageIndexChanged +=new DataGridPageChangedEventHandler(DataGrid_PageIndexChanged);
    this.ItemDataBound +=new DataGridItemEventHandler(DataGrid_ItemDataBound);
    this.HeaderStyle.HorizontalAlign =  System.Web.UI.WebControls.HorizontalAlign.Center;
    this.AllowPaging = true;
    this.PagerStyle.PrevPageText = "上页";
    this.PagerStyle.NextPageText = "下页"; if(this.ViewState["_isPostBack"] == null)
    {
    this.ViewState.Add("_isPostBack",false);
    }
    else
    {
    this.ViewState.Add("_isPostBack",true);
    } }
    private bool isSelect = false;
    public bool IsSelect
    {
    get
    {
    return this.isSelect;
    }
    set
    {
    this.isSelect = value;
    this.ViewState["_isSelect"] = value;
    }
    }
    private bool isShowSerial = false;
    public bool IsShowSerial
    {
    get
    {
    return this.isShowSerial;
    }
    set
    {
    this.isShowSerial = value;
    }
    }
    public void BindDataSource(object DataSource)
    {
    try
    {
    this.DataSource = DataSource; if(this.IsShowSerial)
    {
    System.Web.UI.WebControls.BoundColumn col = new BoundColumn();
    col.HeaderText = "No.";
    this.Columns.AddAt(0,col);
    this.Columns[0].ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
    }
    if(this.isSelect)
    {
    System.Web.UI.WebControls.BoundColumn colSelect = new BoundColumn();
    colSelect.HeaderText = "√";
    this.Columns.AddAt(0,colSelect);
    this.Columns[0].ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
    } this.Pagination();
    }
    catch(System.Exception x)
    {
    this.errMessage = x.Message;
    }
    }
    public void Pagination()
    {
    //this.PagerStyle.Mode = System.Web.UI.WebControls.PagerMode.NumericPages;
    this.PagerStyle.Position = System.Web.UI.WebControls.PagerPosition.Bottom;
    this.PagerStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
    try
    {
    this.DataBind();
    }
    catch(System.Exception x ){
    this.errMessage = x.Message;
    } } private void DataGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
    this.CurrentPageIndex = e.NewPageIndex;
    this.Pagination();
    }
    private string selectValues = "";
    public string GetSelectValues()
    {
    return this.selectValues;

    }
    //private bool isPostBack = false;
    public bool IsPostBack{
    get{
    if(this.ViewState["_isPostBack"] == null){
    return false;
    }
    else
    {
    return Convert.ToBoolean(this.ViewState["_isPostBack"].ToString());
    } }
    } private void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
    {

    //this.isSelect = Convert.ToBoolean(this.ViewState["_isSelect"].ToString());
    if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item){ int n = e.Item.Cells[0].Controls.Count;
    if(n > 0)
    {
    string name = e.Item.Cells[0].Controls[0].GetType().ToString();
    object obj = e.Item.Cells[0].Controls[0];
    if( obj != null)
    {
    CheckBox x =(CheckBox)obj;
    if(x.Checked)
    {
    this.selectValues += "true,";
    }
    }
    }
    if(this.isSelect)
    {
    CheckBox cbx = new CheckBox();
    //cbx.ID = "SelectBox";
    e.Item.Cells[0].Controls.Add(cbx);
    if(this.IsShowSerial){
    e.Item.Cells[1].Text = (e.Item.ItemIndex + this.PageSize * this.CurrentPageIndex+1).ToString();
    }
    }
    else{
    e.Item.Cells[0].Text = (e.Item.ItemIndex + this.PageSize * this.CurrentPageIndex+1).ToString();
    if(this.IsShowSerial)
    {
    e.Item.Cells[0].Text = (e.Item.ItemIndex + this.PageSize * this.CurrentPageIndex+1).ToString();
    } }

    }
    }
    }
      

  6.   

    楼上的!可以发给我吗?
    [email protected]
      

  7.   


    把Email留下 
    有本书
    ASP.NET服务器控件与组件编程
      

  8.   

    [email protected] 麻烦楼上的仁兄,我也顶一本。
      

  9.   

    [email protected]
    ASP.NET服务器控件与组件编程
    发我一本
      

  10.   

    asp.net服务器控件高级编程
    源码下载http://support.apress.com/1861005644/5644.zip
      

  11.   

    [email protected]
    给我一份 谢谢
      

  12.   

    给我一本,谢谢
    [email protected]