`

web自定义控件示例,一个自动分页的datagrid例子

 
阅读更多

以下是一个web自定义的示例,几年前写的,写得也不是很好,权当抛砖引玉。

主要实现datagrid的分页功能:

调用使用方法:

this.DataGrid1.ConnectionString = DataClass.ConnectionString; //这里指定一个连接字串。
this.DataGrid1.strSQL = strSQL;
this.DataGrid1.DataBind();

如果当前的sql中有identitykey,则必须指定

this.DataGrid1.IdentityKey = "字段";

然后绑定。

如果是acesss数据库

this.DataGrid1.bIsAccess = true;

还有几个其他的可选参数,看看代码就明白了。

usingSystem;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Data.SqlClient;
usingSystem.Drawing;
usingSystem.Data.OleDb;

namespaceZFControls
...{
/**////<summary>
///DataGrid
///实现功能
///</summary>

[
ToolboxData(
"<{0}:DataGridrunat=server></{0}:DataGrid>"),
ToolboxBitmap(
typeof(ZFControls.DataGrid),"Grid.bmp")

]
publicclassDataGrid:System.Web.UI.WebControls.DataGrid,IPostBackEventHandler
...{


publicDataGrid()
...{
if(this.Context==null)
...{
this.ShowFooter=true;//显示设计视图
}

}




privateintCurrentPageNo
...{
get
...{

if(ViewState["PageNo"]==null)
...{
ViewState[
"PageNo"]=1;
}

return(int)ViewState["PageNo"];
}

set
...{
ViewState[
"PageNo"]=value;
}

}


/**////<summary>
///是否在列表中显示记录数,默认为True
///</summary>

privateboolShowRecordCount
...{
get
...{

if(ViewState["ShowRecordCount"]==null)
...{
ViewState[
"ShowRecordCount"]=true;
}

return(bool)ViewState["ShowRecordCount"];
}

set
...{
ViewState[
"ShowRecordCount"]=value;
}

}


/**////<summary>
///是否使用默认的样式默认为true
///</summary>

publicboolbDefaultStyle
...{
get
...{

if(ViewState["DefaultStyle"]==null)
...{
ViewState[
"DefaultStyle"]=true;
}

return(bool)ViewState["DefaultStyle"];
}

set
...{
ViewState[
"DefaultStyle"]=value;
}

}


publicstringSortExpression
...{
get
...{
if(ViewState["SortExpression"]==null)
...{
ViewState[
"SortExpression"]="";
}

return(string)ViewState["SortExpression"];
}

set
...{
ViewState[
"SortExpression"]=value;
}

}


publicboolbIsAccess
...{
get
...{
if(ViewState["IsAccess"]==null)
...{
ViewState[
"IsAccess"]=false;
}

return(bool)ViewState["IsAccess"];
}

set
...{
ViewState[
"IsAccess"]=value;
}

}


privateintRecordCount
...{
get
...{
if(ViewState["RecordCount"]==null)
...{
ViewState[
"RecordCount"]=0;
}

return(int)ViewState["RecordCount"];
}

set
...{
ViewState[
"RecordCount"]=value;
}

}

publicstringIdentityKey
...{
get
...{
if(ViewState["IdentityKey"]==null)
...{
ViewState[
"IdentityKey"]="";
}

return(string)ViewState["IdentityKey"];
}

set
...{
ViewState[
"IdentityKey"]=value;
}

}

privateintPageCount1
...{
get
...{
if(this.Context==null)return0;

if(this.RecordCount%this.PageSize==0)
returnthis.RecordCount/this.PageSize;
else
returnConvert.ToInt32(this.RecordCount/this.PageSize)+1;
}



}



privateSystem.Web.UI.WebControls.DataGridItemobjFooterItem;//footerItem

publicstringstrSQL
...{
get
...{
if(ViewState["strSQL"]==null)
...{
ViewState[
"strSQL"]="";
}

return(string)ViewState["strSQL"];
}

set
...{
if((string)value!=this.strSQL)
...{
this.CurrentPageNo=1;//更改了strSQL,重置参数
this.RecordCount=0;

}



ViewState[
"strSQL"]=value;

}

}


publicstringConnectionString
...{
get
...{
if(ViewState["ConnectionString"]==null)
...{
ViewState[
"ConnectionString"]="";
}

return(string)ViewState["ConnectionString"];
}

set
...{
ViewState[
"ConnectionString"]=value;
}

}


publicstringImagePath
...{
get
...{
if(ViewState["ImagePath"]==null)
...{
ViewState[
"ImagePath"]="../images/";
}

return(string)ViewState["ImagePath"];
}

set
...{
ViewState[
"ImagePath"]=value;

}

}


privatestringOldSortExpression
...{
get
...{
if(ViewState["OldSortExpression"]==null)
...{
ViewState[
"OldSortExpression"]="";
}

return(string)ViewState["OldSortExpression"];
}

set
...{
ViewState[
"OldSortExpression"]=value;
}

}


publicboolShowNoRecordMsg
...{
get
...{
if(ViewState["ShowNoRecordMsg"]==null)
...{
ViewState[
"ShowNoRecordMsg"]=true;
}

return(bool)ViewState["ShowNoRecordMsg"];
}

set
...{
ViewState[
"ShowNoRecordMsg"]=value;
}

}









privatestringGetStyleString()
...{
stringres="";
foreach(stringsKeyinthis.Style.Keys)
...{
res
+=sKey+":"+this.Style[sKey]+";";
}

returnres;



}





protectedoverridevoidOnSortCommand(DataGridSortCommandEventArgse)
...{


stringsSort=e.SortExpression.Trim();
if(this.SortExpression.Trim().Split('')[0]==e.SortExpression)
...{
sSort
=this.SortExpression;
}


stringdirect="ASC";
if(sSort.IndexOf("")>-1)
...{
direct
=sSort.Split('')[1];


if(direct.ToUpper()=="ASC")
...{
direct
="DESC";


}

else
...{
direct
="ASC";

}



}



sSort
=sSort.Split('')[0]+""+direct;

if(this.OldSortExpression!="")
...{
DataGridColumnoOldCol
=this.GetColumnBySortExpression(this.OldSortExpression);
oOldCol.HeaderText
=oOldCol.HeaderText.Split('')[0];
}


DataGridColumncol
=GetColumnBySortExpression(e.SortExpression);

if(direct=="ASC")
...{
col.HeaderText
=col.HeaderText.Split('')[0]+"<fontclass='gridarrow'face='webdings'>5</font>";
}

else
...{
col.HeaderText
=col.HeaderText.Split('')[0]+"<fontclass='gridarrow'face='webdings'>6</font>";
}

this.OldSortExpression=e.SortExpression;
this.SortExpression=sSort;
this.DataBind();
}


privateDataGridColumnGetColumnBySortExpression(stringsort)
...{
for(inti=0;i<this.Columns.Count;i++)
...{
if(this.Columns[i].SortExpression==sort.Split('')[0])
...{
returnthis.Columns[i];
}

}


returnnull;
}







protectedoverridevoidOnItemCreated(DataGridItemEventArgse)
...{



if(e.Item.ItemType==ListItemType.Footer)
...{

this.objFooterItem=e.Item;//将它保存下来,目前还不能取得它的Visible属性,最后再处理


}

elseif(e.Item.ItemType==ListItemType.Item
||e.Item.ItemType==ListItemType.AlternatingItem)
...{
e.Item.Attributes.Add(
"onmouseover","javascript:returnDataGridOnMouseOver();");
e.Item.Attributes.Add(
"onmouseout","javascript:returnDataGridOnMouseOut();");

}


base.OnItemCreated(e);
}







privatestringGetPagerText()
...{

stringres=@"<!--{3}-->
<tablealign='right'>
<TR>
<TD>
<span{0}{9}title='回到首页'onclick=""if(this.disabled)return;hidAction_{2}.value='1';btnPager_{2}.click();""style='CURSOR:hand;;border:solid1px#ffffff;padding-right:2px;'><fontface='webdings'>7</font>[首页]</span>
</TD>
<TD>
<span{0}{9}title='回到上一页'onclick=""if(this.disabled)return;hidAction_{2}.value='2';btnPager_{2}.click();""style='CURSOR:hand;border:solid1px#ffffff;padding-right:2px;'><fontface='webdings'>3</font>上页</span>
</TD>
<TD>
<span{1}{9}title='回到下一页'onclick=""if(this.disabled)return;hidAction_{2}.value='3';btnPager_{2}.click();""style='CURSOR:hand;border:solid1px#ffffff;padding-right:2px;'>下页<fontface='webdings'>4</font></span>
</TD>
<TD>
<span{1}{9}title='回到最后一页'onclick=""if(this.disabled)return;hidAction_{2}.value='4';btnPager_{2}.click();""style='CURSOR:hand;border:solid1px#ffffff;padding-right:2px;'>[末页]<fontface='webdings'>8</font></span>
</TD>
<TD>
<spanid='lblCurrentIndex'style='CURSOR:hand'>[{4}/{8}页]</span>
</TD><TD>
<spanid='tbl1'style='CURSOR:hand;height:20px;border:solid0px#e0e0e0;padding:2px;'></TD><TD>{10}</TD><TD>跳到</TD><TD></span><inputname='txtGoPage_{2}'value='{7}'type='text'id='txtGoPage'class='textbox1'style='width:20px;height:18px'/>
</TD><TD><INPUTclass='btnPager'onclick=""hidAction_{2}.value='5';btnPager_{2}.click();""type=buttonvalue='GO'></TD><TD>
<spanid='tbl2'style='CURSOR:hand;height:20px;border:solid0px#e0e0e0;padding:2px;'>每页显示</span></TD><TD><inputname='txtRowsPager_{2}'type='text'id='txtRowsPager'value='{5}'class='textbox1'style='width:20px;height:18px'/></TD><TD><INPUTclass='btnPager'onclick=""hidAction_{2}.value='6';btnPager_{2}.click();""type=buttonvalue=重置>
</TD><TD><inputname='hidAction_{2}'id='hidAction_{2}'type='hidden'/>
";
if(this.Context!=null)//非设计视图
...{
res
+=@"
<inputtype='button'name='btnPager_{2}'id='btnPager_{2}'{6}value='Button'id='btnPager_{2}'style='DISPLAY:none'/>
";
}

res
+=@"</TD><TD>
</TR></TABLE>
";




//System.Web.HttpContext.Current.Response.Write(System.Web.HttpContext.Current.Server.HtmlEncode(res));
//System.Web.HttpContext.Current.Response.Flush();
stringsP0=this.CurrentPageNo>1?"":"disabled";
stringsP1=this.CurrentPageNo<this.PageCount1?"":"disabled";
stringsP2=this.ID;
stringsP3=this.ImagePath;
stringsP4="<fontcolor='red'>"+this.CurrentPageNo.ToString()+"</font>";
stringsP5=this.PageSize.ToString();
stringsP6="onclick="javascript:"+this.Page.GetPostBackEventReference(this,"btnPager_"+sP2)+""";
stringsP7=this.CurrentPageNo.ToString();
//System.Web.HttpContext.Current.Response.Write(this.PageCount1+"**");

stringsP8="<fontcolor='red'>"+this.PageCount1.ToString()+"</font>";
stringsP9="onmouseover='javascript:{0}_PagerOnMouseOver(this);'onmouseout='javascript:{0}_PagerOnMouseOut(this);'onmousedown='javascript:{0}_PagerOnMouseDown(this);'onmouseup='javascript:{0}_PagerOnMouseUp(this);'";
stringsP10="";
if(this.ShowRecordCount)//显示记录数
...{
sP10
="[<fontcolor='red'>"
+(((this.CurrentPageNo-1)*this.PageSize)+1).ToString()+"</font>-<fontcolor='red'>"
+(this.CurrentPageNo*this.PageSize<this.RecordCount?this.CurrentPageNo*this.PageSize:this.RecordCount).ToString()+"</font>/<fontcolor='red'>"+this.RecordCount.ToString()+"</font>条]";
}

sP9
=String.Format(sP9,sP2);
res
=String.Format(res,sP0,sP1,sP2,sP3,sP4,sP5,sP6,sP7,sP8,sP9,sP10);


stringres1=@"
<SCRIPTLANGUAGE='javascript'>
<!--
function{0}_PagerOnMouseOver(obj)
{
if(obj.disabled)return;obj.runtimeStyle.cssText='border-right:solid1pxgray;border-bottom:solid1pxgray';
}
function{0}_PagerOnMouseOut(obj)
{
if(obj.disabled)return;obj.runtimeStyle.cssText='';
}
function{0}_PagerOnMouseDown(obj)
{
if(obj.disabled)return;
obj.runtimeStyle.cssText='border-bottom:solid1pxwhite;border-right:solid1pxwhite;border-top:solid1pxgray;border-left:solid1pxgray;';
}
function{0}_PagerOnMouseUp(obj)
{
if(obj.disabled)return;obj.runtimeStyle.cssText='border-top:solid1pxwhite;border-left:solid1pxwhite;border-bottom:solid1pxgray;border-right:solid1pxgray;';
}
//-->
</SCRIPT>
<!--********************************************--->
";
//res1=String.Format(res1,sP2);
res1=res1.Replace("{0}",sP2);
returnres+res1;
}



protectedoverridevoidOnPreRender(EventArgse)
...{
//base.OnPreRender(e);
//return;
if(bDefaultStyle)//默认的样式
...{
this.BorderColor=(Color)newSystem.Drawing.ColorConverter().ConvertFromString("#E3EDF5");
this.Attributes["Class"]="GridTable";
}
//处理FoooterItem
//找到第一个Visible=True的列
if(this.objFooterItem!=null)
...{
inti=0;
for(i=0;i<this.Columns.Count;i++)
...{
if(this.Columns[i].Visible)
...{
break;
}

}



while(this.objFooterItem.Cells.Count>i+1)
...{
objFooterItem.Cells.RemoveAt(
0);
}

objFooterItem.Cells[i].ColumnSpan
=this.Columns.Count-i;
if(this.bDefaultStyle)
...{
objFooterItem.Cells[i].Attributes[
"class"]="t1";
}

if(this.Items.Count==0&&this.ShowNoRecordMsg)//没有记录
...{
this.objFooterItem.Cells[i].Text=@"<tablewidth='100%'cellspacing='0'cellpadding='0'><TR><TDheight='20px'style='color:gray'align='center'>信息:没有查询到任何记录!</td></tr>
</table>
";
}

else
...{
this.objFooterItem.Cells[i].HorizontalAlign=HorizontalAlign.Right;
this.objFooterItem.Cells[i].Text=this.GetPagerText();
this.objFooterItem.Cells[i].Height=22;
//e.Item.Cells[0].Style.Add("border-top","solid2px#336699");
}

}





if(this.HeaderStyle.CssClass=="")
...{
this.HeaderStyle.CssClass="gridheader";
}

if(this.ItemStyle.CssClass=="")
...{
this.ItemStyle.CssClass="t1";
}

if(this.AlternatingItemStyle.CssClass=="")
...{
this.AlternatingItemStyle.CssClass="t2";
}


this.ShowFooter=true;
base.OnPreRender(e);
}


















[Bindable(
true),
Category(
"Appearance"),
DefaultValue(
"")]
/**////<summary>
///将此控件呈现给指定的输出参数。
///</summary>
///<paramname="output">要写出到的HTML编写器</param>


protectedoverridevoidRender(HtmlTextWriteroutput)
...{

if(this.Context==null)//设计
...{
output.Write(
"<divstyle='width:100%;border:solid1px#336699'>");

output.Write(
"<fontcolor='orange'>请注意:<BR>1、必须指定的参数:ConnectString,strSQL<BR>2、如果查询中只有一张表且有IdentityKey必须指定该Key</font>");
}

base.Render(output);

if(this.Context==null)
...{
output.Write(
this.GetPagerText());
output.Write(
"<DIV>");
}



}


/**////<summary>
///利用存储过程进行分页
///</summary>
///<paramname="strSQl">sql</param>
///<paramname="PrimaryKey">关键字段,一般为表的主健</param>
///<paramname="PageNo">当前页从1开始</param>
///<paramname="PageSize">页面大小</param>
///<paramname="SortExpression">排序表达式</param>
///<paramname="RecordCount">记录总数</param>
///<returns></returns>

publicDataSetGetSqlResult(stringstrSQL,stringPrimaryKey,intPageNo,intPageSize,stringSortExpression,refintRecordCount)
...{
SqlConnectionconn
=null;
SqlCommandcmd
=null;
SqlDataAdapterdapt
=null;
try
...{
conn
=newSqlConnection(this.ConnectionString);

cmd
=newSqlCommand("GetPageResult",conn);
cmd.CommandTimeout
=60000;
cmd.CommandType
=CommandType.StoredProcedure;
SqlParameterpSql
=cmd.Parameters.Add("@sql",SqlDbType.NVarChar,4000);
pSql.Value
=strSQL;
SqlParameterpPKey
=cmd.Parameters.Add("@PKey",SqlDbType.VarChar,50);
pPKey.Value
=PrimaryKey;
SqlParameterpPageNo
=cmd.Parameters.Add("@PageNo",SqlDbType.Int,4);
pPageNo.Value
=PageNo;
SqlParameterpPageSize
=cmd.Parameters.Add("@PageSize",SqlDbType.Int,4);
pPageSize.Value
=PageSize;
SqlParameterpSort
=cmd.Parameters.Add("@sort",SqlDbType.VarChar,50);
pSort.Value
=SortExpression;
SqlParameterpRecordCount
=cmd.Parameters.Add("@RecordCount",SqlDbType.Int,4);
//pRecordCount.Value=SortExpression;
pRecordCount.Direction=ParameterDirection.Output;
dapt
=newSqlDataAdapter(cmd);
conn.Open();
DataSetds
=newDataSet();
dapt.Fill(ds,
"Table1");
RecordCount
=(int)pRecordCount.Value;
returnds;

}

catch(Exceptione)
...{
throw(e);
//returnnull;
}

finally
...{
if(conn!=null)
conn.Dispose();
if(cmd!=null)
cmd.Dispose();
if(dapt!=null)
dapt.Dispose();
}


}


/**////<summary>
///利用存储过程进行分页
///</summary>
///<paramname="strSQl">sql</param>
///<paramname="PrimaryKey">关键字段,一般为表的主健</param>
///<paramname="PageNo">当前页从1开始</param>
///<paramname="PageSize">页面大小</param>
///<paramname="SortExpression">排序表达式</param>
///<paramname="RecordCount">记录总数</param>
///<returns></returns>

publicDataSetGetAccessResult(stringstrSQL,stringPrimaryKey,intPageNo,intPageSize,stringSortExpression,refintRecordCount)
...{


DataSetds
=newDataSet();
if(System.Web.HttpContext.Current.Session[this.Page.ToString()]==null||(!this.Page.IsPostBack))
...{

OleDbConnectionconn
=null;
OleDbDataAdapterdapt
=null;
try
...{


conn
=newOleDbConnection(this.ConnectionString);
conn.Open();
dapt
=newOleDbDataAdapter(strSQL,conn);
//DataSetds=newDataSet();
dapt.Fill(ds,"Table1");
System.Web.HttpContext.Current.Session[
this.Page.ToString()]=ds;
}

catch(Exceptione)
...{
throw(e);
//returnnull;
}

finally
...{
if(conn!=null)
conn.Dispose();

if(dapt!=null)
dapt.Dispose();
}

}

else
...{
ds
=(DataSet)System.Web.HttpContext.Current.Session[this.Page.ToString()];
}


DataViewdv
=ds.Tables[0].DefaultView;
if(SortExpression!="")
dv.Sort
=SortExpression;
RecordCount
=dv.Count;

DataTabledt
=ds.Tables[0].Clone();
intiStart=(PageNo-1)*PageSize+1;
intiEnd=PageNo*PageSize;
//System.Web.HttpContext.Current.Response.Write(this.PageCount1);

if(iEnd>dv.Count)
iEnd
=dv.Count;

if(iStart>0&&iEnd>=iStart)
...{
for(inti=iStart-1;i<iEnd;i++)
...{
DataRowrow
=dt.NewRow();
row.ItemArray
=dv[i].Row.ItemArray;

dt.Rows.Add(row);
}

}

//ds=null;
dv=null;
ds
=newDataSet();
ds.Tables.Add(dt);
returnds;

}



privatestringGetRequestValue(stringsKey)
...{
objecto=this.Page.Request.Form[sKey];
if(o!=null)
...{
returno.ToString().Trim();
}

return"";
}




publicoverridevoidDataBind()
...{
if(this.Context==null)
...{
base.DataBind();
return;
}

if(this.ConnectionString=="")
...{
throw(newException("没有指定ConnectionString"));
}

if(this.strSQL=="")
...{
throw(newException("没有指定strSQL"));
}


intiCount=0;
//AddBYzhaofeng2004-11-19
if(this.CurrentPageNo>this.PageCount1)
...{
this.CurrentPageNo=this.PageCount1;
}

if(this.CurrentPageNo==0)
this.CurrentPageNo=1;
//AddEnd
DataSetds=null;
if(this.bIsAccess)
ds
=this.GetAccessResult(this.strSQL,this.IdentityKey,this.CurrentPageNo,this.PageSize,this.SortExpression,refiCount);
else

ds
=this.GetSqlResult(this.strSQL,this.IdentityKey,this.CurrentPageNo,this.PageSize,this.SortExpression,refiCount);

this.RecordCount=iCount;
this.DataSource=ds.Tables[0].DefaultView;
base.DataBind();
}


privatevoidDoPager()
...{
stringsAcionType=this.GetRequestValue("hidAction_"+this.ID);
switch(sAcionType)
...{
case"1":
this.CurrentPageNo=1;
break;
case"2":
if(this.CurrentPageNo>1)
...{
this.CurrentPageNo=this.CurrentPageNo-1;
}

else
return;
break;
case"3":

if(this.CurrentPageNo<this.PageCount1)
...{
this.CurrentPageNo=this.CurrentPageNo+1;
}

else
return;
break;
case"4":
if(this.CurrentPageNo!=this.PageCount1)
...{
this.CurrentPageNo=this.PageCount1;
}

else
return;
break;
case"5"://Goto
stringsCurPage=this.GetRequestValue("txtGoPage_"+this.ID);
if(CCConvert.IsInt32(sCurPage))
...{
intiCurrentPageNo=Convert.ToInt32(sCurPage);
if(iCurrentPageNo>0&&iCurrentPageNo<=this.PageCount1)
...{
this.CurrentPageNo=iCurrentPageNo;
}

}

else
return;
break;
case"6"://重设显示页数
stringsPageSize=this.GetRequestValue("txtRowsPager_"+this.ID);
if(CCConvert.IsInt32(sPageSize))
...{
intiPage=Convert.ToInt32(sPageSize);
if(iPage>0)
this.PageSize=iPage;
else
return;
}

else
return;
break;
default:
return;

}



this.DataBind();
}

IPostBackEventHandler成员#regionIPostBackEventHandler成员

publicvoidRaisePostBackEvent(stringeventArgument)
...{
if(eventArgument=="btnPager_"+this.ID)
...{
this.DoPager();
}


}

protectedoverridevoidOnInit(EventArgse)
...{


base.OnInit(e);
}




#endregion

}

}

用到的存储过程:

SETQUOTED_IDENTIFIEROFF
GO
SETANSI_NULLSOFF
GO





/*****************************
名称:GetPageResult
功能:得到分页记录集
作者:cpp2017
编写时间:2002-08-17
****************************
*/

CREATEPROCEDUREGetPageResult
@sqlnvarchar(4000),--SqlStatment
@PKeyvarchar(100),---PrimaryKeyName
@PageNoint,--CurrentPageNo
@PageSizeint,--PageSize
@Sortvarchar(50),--SortField
@RecordCountintoutput--RecordCount传出参数
AS
BEGIN


DECLARE@sqlStrNVARCHAR(4000);
---得到记录总数Start
if@RecordCount=-1or@RecordCountisnull
begin
SET@sqlStr='select@count=Count(1)from('+@sql+')asAA';
EXECUTEsp_executesql@sqlStr,N'@countintout',@RecordCountout;
end
---得到记录总数End
--加上排序Start
IF@SortISnotnulland@sort<>''
BEGIN

Set@sort='orderby'+@sort;
END
--加上排序End
IF(@PageNo=1)--第一页
SET@sqlStr='selecttop'+cast(@PageSizeasvarchar(5))+'*FROM('+@sql+')ASAA'+@sort
ELSE

BEGIN
declare@sMaxCountvarchar(10)
declare@sMinCountvarchar(10)
set@sMaxCount=cast(@PageSize*@PageNoasvarchar(5))
set@sMinCount=Convert(nvarchar(10),(@PageNo-1)*@PageSize)


if@PKey!=''or@PKeyisnull--如果有主键,注此key必须是identitykey
begin
SET@sqlStr='selecttop'+@sMaxCount+''+@PKey+'into#tempfrom('+@sql+')asAA'+@sort+';'
Set@sqlStr=@sqlStr+'deletefrom#tempwhere'+@PKey+'in(selecttop'+@sMinCount+''+@PKey+'from#temp);'
SET@sqlStr=@sqlStr+'selectA.*from('+@sql+')ASAINNERJOIN#tempasBONA.'+@PKey+'=B.'+@Pkey+';droptable#temp'
end
else
Begin
SET@sqlStr='selecttop'+@sMaxCount+'*into#tempfrom('+@sql+')asAA'+@sort+';'
SET@sqlStr=@sqlStr+'exec(''altertable#tempaddPrimaryKeyintidentity(1,1);'');deletefrom#tempwherePrimaryKeyin(selecttop'+@sMinCount+'PrimaryKeyFrom#temp)'

SET@sqlStr=@sqlStr+';select*from#temp;droptable#temp'
end
END

EXECUTE(@sqlStr)
print@sqlstr
END
GO
SETQUOTED_IDENTIFIEROFF
GO
SETANSI_NULLSON
GO

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1538109

分享到:
评论

相关推荐

    能用漂亮分页控件及Demo源码

    AspNetPager除提供默认的类似于DataGrid和GridView的PostBack分页方式外,还支持通过Url进行分页,象大多数asp程序中分页一样, Url分页方式允许用户通过在浏览器地址栏中输入相应的地址即可直接进入指定页面,也...

    C#自定义分页控件

    二、AspNetPager支持各种数据绑定控件GridView、DataGrid、DataList、Repeater以及自定义的数据绑定控件的分页功能十分强大。 三、AspNetPager分页控件本身并不显示任何数据,而只显示分页导航元素,数据在页面上的...

    DataGrid+DataPager表格和分页控件的最小示例

    DataGrid+DataPager表格和分页控件的最小示例

    九头鸭分页控件 Url分页方式

    在弹出的选择工具箱项窗口中点击右下角的浏览选择bin文件夹下的DataPage.dll然后点击确定,你会发现工具箱中多了一个DataPage工具直接拖动到界面即可,然后参照例子完成自己的项目分页设置。 本控件供大家免费使用

    AspNetPager 7.2 7.02控件源码与示例

    分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net 1.1)和GridView(asp.net 2.0)控件,但其分页功能并不尽如人意,如可定制性差、无法通过Url实现分页功能等,...

    AspNetPagerv7.4.1分页控件及Demo源码2012919

    分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net 1.1)和GridView(asp.net 2.0)控件,但其分页功能并不尽如人意,如可定制性差、无法通过Url实现分页功能等, ...

    九头鸭.net分页控件 v1.1.rar

    DataPage除提供默认的类似于DataGrid和GridView的PostBack分页方式外,还支持通过Url进行分页,象大多数asp程序中分页一样, Url分页方式允许用户通过在浏览器地址栏中输入相应的地址即可直接进入指定页面,也可以使...

    AspNetPager7.2分页控件及Demo源码

    分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net 1.1)和GridView(asp.net 2.0)控件,但其分页功能并不尽如人意,如可定制性差、无法通过Url实现分页功能等,...

    九头鸭分页控件源码

    DataPage除提供默认的类似于DataGrid和GridView的PostBack分页方式外,还支持通过Url进行分页,象大多数asp程序中分页一样, Url分页方式允许用户通过在浏览器地址栏中输入相应的地址即可直接进入指定页面,也可以使...

    九头鸭.net分页控件DataPage.rar

    DataPage除提供默认的类似于DataGrid和GridView的PostBack分页方式外,还支持通过Url进行分页,象大多数asp程序中分页一样, Url分页方式允许用户通过在浏览器地址栏中输入相应的地址即可直接进入指定页面,也可以使...

    ASP.Net皮肤换肤控件

    分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net 1.1)和GridView(asp.net 2.0)控件,但其分页功能并不尽如人意,如可定制性差、无法通过Url实现分页功能等,...

    asp.net专家疑难解答200问源码

    119.如何在DataGrid中弹出一个详细信息窗口-示例2 120. 如何在DataGrid控件中添加CheckBox控件列 121.如何为DataGrid控件中的删除列添加确认框 122.如何使用DataGrid控件实现主细表 123.如何实现DataGrid控件的...

    AspNetPagerCN:AspNetPager分页控件中文版源代码及示例项目-项目

    AspNetPager AspNetPager分页控件中文版源代码及示例项目分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net 1.1)和GridView(asp.net 2.0)控件,但其分页功能并不...

    EasyUI ComboGrid 集成分页、按键示例

    asyUI ComboGrid 集成分页、按键示例源码 源码描述: 实现的功能: 1、下拉框下拉时出现表格; 2、表格带分页功能; 3、可以使用向上键、向下键在表格中移动选择行数据; 4、可以使用回车键在表格中选中行数据; 5、...

    ASP.NET 各种分页技巧

    AspNetPager支持使用主题(Theme)与皮肤(Skin)统一控件的整体样式,配合asp.net 2.0中的DataSource控件,AspNetPager只需要编写短短几行代码,甚至无需编写任何代码,只需设置几个属性就可以实现分页功能。...

    AspNetPager示例源码学习 7.2

    分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net 1.1)和GridView(asp.net 2.0)控件,但其分页功能并不尽如人意,如可定制性差、无法通过Url实现分页功能等,...

    ASP.NET常见问题集锦.zip

    复合 Web 控件示例(2.0).doc 如何在ASP.Net中把图片存入数据库.txt 如何在DateTime字段里只存储日期部分?.txt 如何用.NET创建Windows服务.doc 委托与事件.doc 学生选课系统事例(老师).txt 学生选课系统...

Global site tag (gtag.js) - Google Analytics