分享
 
 
 

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

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

第一次写,忘记注解,对不住.

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=@"

?

???? ???? ???? ???? ????table?{?font-size:?12px;?border:?0px?;?border-color:?#99CC99?#99CC99?#CCCCCC?#CCCCCC;?cellspacing:1;?bgcolor:#eeeeee;?text-decoration:?blink}

???? ???? ???? ???? ????.SortTitle?{?font-size:?20px;background-color:#FFCC99;COLOR:?blue;CURSOR:?hand}

.title?{?font-size:?20px;background-color:#FFCC99}

???? ???? ???? ???? ????.main?{?background-color:#dddddd}

???? ???? ???? ???? ????.divClass?{?background-color:#FFCC99}

???? ???? ???? ???? ????.gray{COLOR:?gray;FONT-SIZE:?small;??FONT-FAMILY:?Webdings}

????????????????????.active{COLOR:?blue;FONT-SIZE:?small;??FONT-FAMILY:?Webdings;CURSOR:?hand}

????????????????????.expand{FONT-SIZE:?x-small;?COLOR:?black;?FONT-FAMILY:?Webdings;CURSOR:?hand}

????????????????????.delete{FONT-SIZE:?x-small;?COLOR:?red;?FONT-FAMILY:?Webdings;CURSOR:?hand}

????????????????????.edit{FONT-SIZE:?x-small;?COLOR:?blue;?FONT-FAMILY:?Webdings;CURSOR:?hand}

???? ???? ???? ???? ????

";

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());

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有