想自己重新写个控件,修改一下现有的gridview控件,该怎么处理?

解决方案 »

  1.   

    参考
    public class CustomList : DataList {
            //Static constants
            protected const string HTML1 = "<table cellpadding=0 cellspacing=0><tr><td colspan=2>";
            protected const string HTML2 = "</td></tr><tr><td class=paging align=left>";
            protected const string HTML3 = "</td><td align=right class=paging>";
            protected const string HTML4 = "</td></tr></table>";
            private static readonly Regex RX = new Regex(@"^&page=\d+", RegexOptions.Compiled);
            private const string LINK_PREV = "<a href=?page={0}>&#060;&nbsp;Previous</a>";
            private const string LINK_MORE = "<a href=?page={0}>More&nbsp;&#062;</a>";
            private const string KEY_PAGE = "page";
            private const string COMMA = "?";
            private const string AMP = "&";        protected string emptyText;
            private IList dataSource;
            private int pageSize = 10;
            private int currentPageIndex;
            private int itemCount;        override public object DataSource {
                set {
                    //This try catch block is to avoid issues with the VS.NET designer
                    //The designer will try and bind a datasource which does not derive from ILIST
                    try {
                        dataSource = (IList)value;
                        ItemCount = dataSource.Count;
                    }
                    catch {
                        dataSource = null;
                        ItemCount = 0;
                    }
                }
            }        public int PageSize {
                get { return pageSize; }
                set { pageSize = value; }
            }        protected int PageCount {
                get { return (ItemCount - 1) / pageSize; }
            }        virtual protected int ItemCount {
                get { return itemCount; }
                set { itemCount = value; }
            }        virtual public int CurrentPageIndex {
                get { return currentPageIndex; }
                set { currentPageIndex = value; }
            }        public string EmptyText {
                set { emptyText = value; }
            }        public void SetPage(int index) {
                OnPageIndexChanged(new DataGridPageChangedEventArgs(null, index));
            }        override protected void OnLoad(EventArgs e) {
                if (Visible) {
                    string page = Context.Request[KEY_PAGE];
                    int index = (page != null) ? int.Parse(page) : 0;
                    SetPage(index);
                }
            }
            /// <summary>
            /// Overriden method to control how the page is rendered
            /// </summary>
            /// <param name="writer"></param>
            override protected void Render(HtmlTextWriter writer) {            //Check there is some data attached
                if (ItemCount == 0) {
                    writer.Write(emptyText);
                    return;
                }            //Mask the query
                string query = Context.Request.Url.Query.Replace(COMMA, AMP);
                query = RX.Replace(query, string.Empty);           
                // Write out the first part of the control, the table header
                writer.Write(HTML1);            // Call the inherited method
                base.Render(writer);
                
                // Write out a table row closure
                writer.Write(HTML2);            //Determin whether next and previous buttons are required
                //Previous button?
                if (currentPageIndex > 0)
                    writer.Write(string.Format(LINK_PREV, (currentPageIndex - 1) + query));            //Close the table data tag
                writer.Write(HTML3);            //Next button?
                if (currentPageIndex < PageCount)
                    writer.Write(string.Format(LINK_MORE, (currentPageIndex + 1) + query));            //Close the table
                writer.Write(HTML4);
            }        override protected void OnDataBinding(EventArgs e) {            //Work out which items we want to render to the page
                int start = CurrentPageIndex * pageSize;
                int size = Math.Min(pageSize, ItemCount - start);            IList page = new ArrayList();            //Add the relevant items from the datasource
                for (int i = 0; i < size; i++)
                    page.Add(dataSource[start + i]);            //set the base objects datasource
                base.DataSource = page;
                base.OnDataBinding(e);        }        public event DataGridPageChangedEventHandler PageIndexChanged;        virtual protected void OnPageIndexChanged(DataGridPageChangedEventArgs e) {
                if (PageIndexChanged != null)
                    PageIndexChanged(this, e);
            }
        }
      

  2.   

    给你个界面函数吧,自己写的一个控件类,看出是啥控件来了没?嘿嘿~~完全手工的。
    public static void ShowPageInfo(int curpg,int pagesize,string pagename,string headername,string footername, ref DataView dv,ref Repeater List,bool IsForm)
    {
    int curpage,pages,sum,n,i;
    string headermsg,footermsg,firstmsg,lastmsg,backmsg,forwardmsg;
    HtmlTableCell tdh=null,tdf=null;
    sum=dv.Count;
    curpage=curpg;
    pages=sum/pagesize;
    if(sum%pagesize!=0)pages++;
    if(curpage>pages)curpage=pages;
    else if(curpage<1)curpage=1;
    n=pagesize*(curpage-1);
    for(i=0;i<n;i++)dv.Delete(0);
    while(dv.Count>pagesize)dv.Delete(dv.Count-1);
    List.DataSource=dv;
    List.DataBind();
    if(!(headername==""||headername==null))tdh=(HtmlTableCell)List.Controls[0].FindControl(headername);
    if(!(footername==""||footername==null))tdf=(HtmlTableCell)List.Controls[List.Controls.Count-1].FindControl(footername);
    headermsg="总记录:&nbsp;&nbsp;<font color='#FF0000'>"+sum.ToString()+"</font>&nbsp;&nbsp;&nbsp;&nbsp;每页:&nbsp;&nbsp<font color='#FF0000'>"+pagesize.ToString()+"</font>&nbsp;&nbsp;&nbsp;&nbsp;总页数: <font color='#FF0000'>"+pages.ToString()+"</font>&nbsp;&nbsp;&nbsp;&nbsp;";
    if(!IsForm)
    {
    if(pages>1&&curpage>1)firstmsg="<a href=\'"+pagename+"?CurPage=1\'>首页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    else firstmsg="第一页&nbsp;&nbsp;&nbsp;&nbsp;";
    if(pages>1&&curpage<pages)lastmsg="<a href=\'"+pagename+"?CurPage="+pages.ToString()+"\'>最后页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    else lastmsg="尾页&nbsp;&nbsp;&nbsp;&nbsp;";
    if(curpage>1)backmsg="<a href=\'"+pagename+"?CurPage="+(curpage-1).ToString()+"\'>上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    else backmsg="上一页&nbsp;&nbsp;&nbsp;&nbsp;";
    if(curpage<pages)forwardmsg="<a href=\'"+pagename+"?CurPage="+(curpage+1).ToString()+"\'>下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    else forwardmsg="下一页&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    else
    {
    if(pages>1&&curpage>1)firstmsg="<a OnClick=\'JavaScript:SendPage(\"1\");\'>首页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    else firstmsg="首页&nbsp;&nbsp;&nbsp;&nbsp;";
    if(pages>1&&curpage<pages)lastmsg="<a OnClick=\'JavaScript:SendPage(\""+pages.ToString()+"\");\'>尾页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    else lastmsg="尾页&nbsp;&nbsp;&nbsp;&nbsp;";
    if(curpage>1)backmsg="<a OnClick=\'JavaScript:SendPage(\""+(curpage-1).ToString()+"\");\'>上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    else backmsg="上一页&nbsp;&nbsp;&nbsp;&nbsp;";
    if(curpage<pages)forwardmsg="<a OnClick=\'JavaScript:SendPage(\""+(curpage+1).ToString()+"\");\'>下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    else forwardmsg="下一页&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    footermsg="当前页:&nbsp;&nbsp;<font color='#FF0000'>"+curpage.ToString()+"</font>";
    if(tdh!=null)tdh.InnerHtml="&nbsp;&nbsp;"+headermsg+firstmsg+backmsg+forwardmsg+lastmsg+footermsg+"&nbsp;&nbsp;";
    if(tdf!=null)tdf.InnerHtml="&nbsp;&nbsp;"+headermsg+firstmsg+backmsg+forwardmsg+lastmsg+footermsg+"&nbsp;&nbsp;";
    return;
    }
      

  3.   

    具体内容我也懂的写,只是不知道要写在哪里?
    我写了这句:
    public class WebGridView:GridView
    {
    ...
    }
    就已经出错了,说找不到gridview
      

  4.   

    要继承gridview,需要在前面写上什么?
      

  5.   

    已经自己解决了,需要调用using System.Web.UI.WebControls;
    using System.ComponentModel;