·您的位置: 首页 » 资源教程 » 编程开发 » ASP » 一个自定义的可以分页,排序,扩展显示GRID控件

一个自定义的可以分页,排序,扩展显示GRID控件

类别: ASP教程  评论数:0 总得分:0
第一次写,忘记注解,对不住.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Xml;

namespace Grid
{

public class IDArgs : System.EventArgs
{
private string id;

//Constructor.
//
public IDArgs(string Id)
{
this.id =Id;

}

// The NumRings property returns the number of rings
// that the alarm clock has sounded when the alarm event
// is generated.
//
public string ID
{
get { return this.id ;}
}

}

///
/// Summary description for WebCustomControl1.
///
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1 runat=server>")]
public class WebCustomControl1 : System.Web.UI.WebControls.WebControl, IPostBackEventHandler
{

public string EditUrl
{
get
{
if(this.ViewState["EditUrl"]!=null) return (string)this.ViewState["EditUrl"];
else return "";
}
set
{
this.ViewState["EditUrl"]=value;
}
}

public string ExpandColumn
{
get
{
if(this.ViewState["ExpandColumn"]!=null) return (string)this.ViewState["ExpandColumn"];
else return "";
}
set
{
this.ViewState["ExpandColumn"]=value;
}
}

//set paging

public int IsPaging
{
get
{
if(this.ViewState["IsPaging"]!=null) return (int)this.ViewState["IsPaging"];
else return 0;
}
set
{
this.ViewState["IsPaging"]=value;
}
}

public int PageCount
{
get
{
if(this.ViewState["PageCount"]!=null) return (int)this.ViewState["PageCount"];
else return 0;
}
set
{
this.ViewState["PageCount"]=value;
}
}

public int CurrentPage
{
get
{
if(this.ViewState["CurrentPage"]!=null) return (int)this.ViewState["CurrentPage"];
else return 1;
}
set
{
this.ViewState["CurrentPage"]=value;
}
}

//set sort
public int IsSort
{
get
{
if(this.ViewState["IsSort"]!=null) return (int)this.ViewState["IsSort"];
else return 0;
}
set
{
this.ViewState["IsSort"]=value;
}
}

public int sortColumn
{
get
{
if(this.ViewState["sortColumn"]!=null) return (int)this.ViewState["sortColumn"];
else return -1;
}
set
{
this.ViewState["sortColumn"]=value;
}
}



public string sortColumnName
{
get
{
if(this.ViewState["sortColumnName"]!=null) return (string)this.ViewState["sortColumnName"];
else return "";
}
set
{
this.ViewState["sortColumnName"]=value;
}
}


public string sortOrder
{
get
{
if(this.ViewState["sortOrder"]!=null) return (string)this.ViewState["sortOrder"];
else return "ASC";
}
set
{
this.ViewState["sortOrder"]=value;
}
}
public DataSet source
{
get
{
return (DataSet)this.ViewState["source"];
}
set
{

this.ViewState["source"]=value;
}
}

public event EventHandler Delete;
public event EventHandler Refresh;


public void RaisePostDataChangedEvent()
{

// IPostBackDataHandler 协定的一部分。如果曾经从 LoadPostData 方法返回真
// (表示需要引发更改通知),则被调用。由于
// 始终返回假,则此方法只是一个空操作。
}

// protected void OnChange(EventArgs e)
// {
// Sort(this, e);
// }
public void RaisePostBackEvent(String eventArgument)
{
if (eventArgument.IndexOf("|")>-1)
{

IDArgs ide=new IDArgs(eventArgument.Substring(eventArgument.IndexOf("|")+1));
if (Delete!=null)
{
Delete(this,ide);

}
return;
}
string flag="";
switch(eventArgument)
{
case "first":this.CurrentPage =1;break;
case "prev":this.CurrentPage -- ;break;
case "next":this.CurrentPage ++ ;break;
case "last":this.CurrentPage =this.PageCount;break;
case "":break;
default:
{
DataTable dt=source.Tables[0];
int lastColumn=sortColumn;
for(int i=0;i if (eventArgument==dt.Columns[i].ColumnName)
{
sortColumn=i;
break;
}

if (lastColumn==sortColumn) { if (this.sortOrder=="DESC") sortOrder="ASC"; else sortOrder="DESC";}
else sortOrder="ASC";
sortColumnName=eventArgument;
break;
}
}

// if ( flag=="sort")
// {
// if(this.IsSort ==0)
// {
// return;
// }
// }

if ( Refresh!=null) Refresh(this,EventArgs.Empty );
}



private string WriteScipt()
{
string script=@" ";
string style=@"

";


return script+style;
}

private string writeList()
{

int[] columnWidth=new int[] {20,100,100,100,0};
DataTable dt=source.Tables[0];
string title=(this.IsSort ==0)?"title":"SortTitle";
string list="
";
if (ExpandColumn!="") list+="";

if (this.IsSort==1)
{
string sortstr="";
string sortFlag=(this.sortOrder=="ASC")?"5":"6";
//set header and sort
for(int j=1;j {
if (sortColumn==j)
{
sortstr=""+sortFlag+"";
}

else sortstr="";
if (columnWidth[j]==0)
list+=""+dt.Columns[j].ColumnName+sortstr+"";
else
list+=""+dt.Columns[j].ColumnName+sortstr+"";
}
}
else
{
for(int j=1;j {

if (columnWidth[j]==0)
list+=""+dt.Columns[j].ColumnName+"";
else
list+=""+dt.Columns[j].ColumnName+"";
}
}

list+="L
";
list+="";

list+="";
for(int i=0;i {
list+="";
//expand column
if (ExpandColumn!="")
list+="5 ";
//delete column
list+="r";
//edit column
list+="1";

for(int j=1;j {
list+=""+dt.Rows[i][j].ToString()+"";
}
list+="
";
//expand display
if (ExpandColumn!="")
list+=" desc


--------------------------------------------------------------------------------

"+dt.Rows[i][ExpandColumn].ToString()+"

";
}
list +="
";


if (this.IsPaging ==0)return list;
//set pageing
string paging="";
if ( PageCount<2)
paging="9|3|4|:";
else
{
if (this.CurrentPage==1)
paging="9|3|4|:";
else if (this.CurrentPage ==this.PageCount)
paging="9|3|4|:";
else
paging="9|3|4|:";
}


list +="Total:"+this.PageCount+"Page:"+this.CurrentPage+""+paging;
return list;
}
///
/// Render this control to the output parameter specified.
///
/// The HTML writer to write out to
protected override void Render(HtmlTextWriter output)
{
output.Write(WriteScipt());
output.Write(writeList());
}
}
}
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1