问题描述
谁有GridView用存储过程自定义分页分页的完整例子(C#)给一个
解决方案
解决方案二:
datalist,repeater存储过程分页带1,2,3,4,5,6,7导航的记住把分都给我哦存储过程:直接复制进去CREATEprocup_GetTopicList@a_TableListVarchar(200),@a_TableNameVarchar(30),@a_SelectWhereVarchar(500),@a_SelectOrderIdVarchar(20),@a_SelectOrderVarchar(50),@a_intPageNoint,@a_intPageSizeint,@RecordCountintOUTPUTas/*定义局部变量*/declare@intBeginIDintdeclare@intEndIDintdeclare@intRootRecordCountintdeclare@intRowCountintdeclare@TmpSelectNVarchar(600)/*关闭计数*/setnocounton/*求总共根贴数*/select@TmpSelect='setnocounton;select@SPintRootRecordCount=count(*)from'+@a_TableName+''+@a_SelectWhereexecutesp_executesql@TmpSelect,N'@SPintRootRecordCountintOUTPUT',@SPintRootRecordCount=@intRootRecordCountOUTPUTselect@RecordCount=@intRootRecordCountif(@intRootRecordCount=0)--如果没有贴子,则返回零return0/*判断页数是否正确*/if(@a_intPageNo-1)*@a_intPageSize>@intRootRecordCountreturn(-1)/*求开始rootID*/set@intRowCount=(@a_intPageNo-1)*@a_intPageSize+1/*限制条数*/select@TmpSelect='setnocounton;setrowcount@SPintRowCount;select@SPintBeginID='+@a_SelectOrderId+'from'+@a_TableName+''+@a_SelectWhere+''+@a_SelectOrderexecutesp_executesql@TmpSelect,N'@SPintRowCountint,@SPintBeginIDintOUTPUT',@SPintRowCount=@intRowCount,@SPintBeginID=@intBeginIDOUTPUT/*结束rootID*/set@intRowCount=@a_intPageNo*@a_intPageSize/*限制条数*/select@TmpSelect='setnocounton;setrowcount@SPintRowCount;select@SPintEndID='+@a_SelectOrderId+'from'+@a_TableName+''+@a_SelectWhere+''+@a_SelectOrderexecutesp_executesql@TmpSelect,N'@SPintRowCountint,@SPintEndIDintOUTPUT',@SPintRowCount=@intRowCount,@SPintEndID=@intEndIDOUTPUTif@a_SelectWhere=''or@a_SelectWhereISNULLselect@TmpSelect='setnocountoff;setrowcount0;select'+@a_TableList+'from'+@a_TableName+'where'+@a_SelectOrderId+'between'elseselect@TmpSelect='setnocountoff;setrowcount0;select'+@a_TableList+'from'+@a_TableName+''+@a_SelectWhere+'and'+@a_SelectOrderId+'between'if@intEndID>@intBeginIDselect@TmpSelect=@TmpSelect+'@SPintBeginIDand@SPintEndID'+''+@a_SelectOrderelseselect@TmpSelect=@TmpSelect+'@SPintEndIDand@SPintBeginID'+''+@a_SelectOrderexecutesp_executesql@TmpSelect,N'@SPintEndIDint,@SPintBeginIDint',@SPintEndID=@intEndID,@SPintBeginID=@intBeginIDreturn(@@rowcount)--select@@rowcountGO
解决方案三:
前台代码<table><tr><td><ahref="cgalgd.aspx">更多</a></td></tr><tr><tdvalign="top"align="left"><asp:DataListID="dl1"runat="server"RepeatColumns="3"><ItemTemplate><table><tr><td><ahref='<%#DataBinder.Eval(Container.DataItem,"WZ")%>'style="color:Black"target="_blank"><imgwidth="100px"height="80px"src='<%#DataBinder.Eval(Container.DataItem,"LJ")%>'alt="产品图片"/></a><br/><ahref='<%#DataBinder.Eval(Container.DataItem,"WZ")%>'style="color:Black"target="_blank"><%#strvalue(StripHT(((DataBinder.Eval(Container.DataItem,"JS"))).ToString()),10)%><%--<%#strvalue(StripHT(((System.Data.DataRowView)Container.DataItem)["detail"].ToString()),40)%>--%></a></td></tr></table></ItemTemplate></asp:DataList></td></tr><tr><td><spanclass="high"style="display:none;">第<fontcolor="#CC0000"><asp:Labelid="LabelRow"runat="server"/></font>页|共有<asp:Labelid="LabelPage"runat="server"/>页|<asp:Labelid="LabelRecord"runat="server"/>条信息|<asp:HyperLinkid="HLFistPage"Text="首页"runat="server"/>|<asp:HyperLinkid="HLPrevPage"Text="上一页"runat="server"/>|<asp:HyperLinkid="HLNextPage"Text="下一页"runat="server"/>|<asp:HyperLinkid="HLEndPage"Text="尾页"runat="server"/></span></td></tr></table>
解决方案四:
后台代码usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;usingSystem.Text.RegularExpressions;publicpartialclasscpjsq:System.Web.UI.Page{publicintcurPage=1;//当前页publicinttotalPage=0;//总的页数publicstaticstringitem;protectedvoidPage_Load(objectsender,EventArgse){if(!Page.IsPostBack){if(Request["item"]!=null){item=Request["item"].ToString();}intintPageNo,intPageSize,intPageCount;intPageSize=6;//OK!!!!!if(Request["CurrentPage"]==null){intPageNo=1;}else{intPageNo=Int32.Parse(Request["CurrentPage"]);}SqlConnectionmySqlConnection=newSqlConnection(System.Configuration.ConfigurationSettings.AppSettings["BBB"]);SqlCommandmySqlCommand=newSqlCommand("up_GetTopicList",mySqlConnection);mySqlCommand.CommandType=CommandType.StoredProcedure;SqlParameterworkParm;//newsid,newstitle,newscontent,newsdatetime,newscategory//搜索表字段,以","号分隔workParm=mySqlCommand.Parameters.Add("@a_TableList",SqlDbType.VarChar,200);mySqlCommand.Parameters["@a_TableList"].Value="ID,LJ,JS,WZ";//搜索表名workParm=mySqlCommand.Parameters.Add("@a_TableName",SqlDbType.VarChar,30);mySqlCommand.Parameters["@a_TableName"].Value="cpjs";//搜索条件,如"select*fromaawherea=1andb=2andc=3"则条件为"wherea=1andb=2andc=3"workParm=mySqlCommand.Parameters.Add("@a_SelectWhere",SqlDbType.VarChar,500);mySqlCommand.Parameters["@a_SelectWhere"].Value="whereJSlike'%"+item+"%'";//mySqlCommand.Parameters["@a_SelectWhere"].Value="wherenewsid<>'10000000'";//表主键字段名,必须为INT类型workParm=mySqlCommand.Parameters.Add("@a_SelectOrderId",SqlDbType.VarChar,50);mySqlCommand.Parameters["@a_SelectOrderId"].Value="ID";//排序,可以使用多字段排序但主键字段必需在最前面workParm=mySqlCommand.Parameters.Add("@a_SelectOrder",SqlDbType.VarChar,50);mySqlCommand.Parameters["@a_SelectOrder"].Value="orderbyIDdesc";//页号workParm=mySqlCommand.Parameters.Add("@a_intPageNo",SqlDbType.Int);mySqlCommand.Parameters["@a_intPageNo"].Value=intPageNo;//每页显示数workParm=mySqlCommand.Parameters.Add("@a_intPageSize",SqlDbType.Int);mySqlCommand.Parameters["@a_intPageSize"].Value=intPageSize;//总记录数(存储过程输出参数)workParm=mySqlCommand.Parameters.Add("@RecordCount",SqlDbType.Int);workParm.Direction=ParameterDirection.Output;//当前页记录数(存储过程返回值)workParm=mySqlCommand.Parameters.Add("RowCount",SqlDbType.Int);workParm.Direction=ParameterDirection.ReturnValue;mySqlConnection.Open();dl1.DataSource=mySqlCommand.ExecuteReader();dl1.DataBind();mySqlConnection.Close();Int32RecordCount=(Int32)mySqlCommand.Parameters["@RecordCount"].Value;Int32RowCount=(Int32)mySqlCommand.Parameters["RowCount"].Value;LabelRecord.Text=RecordCount.ToString();LabelRow.Text=intPageNo.ToString();if(GetPageCount(intPageSize,RecordCount)!=1)//总页数不为1时{intPageCount=GetPageCount(intPageSize,RecordCount);LabelPage.Text=intPageCount.ToString();//lbl总页数HLFistPage.Enabled=true;HLEndPage.Enabled=true;HLFistPage.NavigateUrl="cpjsq.aspx?CurrentPage=1";//首页HLEndPage.NavigateUrl="cpjsq.aspx?CurrentPage="+intPageCount;//末页if(intPageNo<intPageCount)//传过来的页码小于总页数{HLNextPage.Enabled=true;HLNextPage.NavigateUrl="cpjsq.aspx?CurrentPage="+Convert.ToString(intPageNo+1);//上一页}else{HLNextPage.Enabled=false;HLEndPage.Enabled=false;}if(intPageNo>1)//传过来的页码大于1{HLPrevPage.Enabled=true;HLPrevPage.NavigateUrl="cpjsq.aspx?CurrentPage="+Convert.ToString(intPageNo-1);//下一页}else{HLPrevPage.Enabled=false;HLFistPage.Enabled=false;}}else{HLFistPage.Enabled=false;HLEndPage.Enabled=false;HLNextPage.Enabled=false;HLPrevPage.Enabled=false;//lblAllPage.Text="1";LabelPage.Text="1";}if(this.LabelRecord.Text=="0"){Response.Write("<script>alert('没有搜索到指定的数据!');</script>");}}}publicstringstrvalue(stringvalue,intlength){if(value.Length>length){value=value.Substring(0,length);value=value+"...";returnvalue;}else{returnvalue;}}publicstringStripHT(stringstrHtml){Regexregex=newRegex("<.+?>",RegexOptions.IgnoreCase);stringstrOutput=regex.Replace(strHtml,"");returnstrOutput;}publicintGetPageCount(introwSize,introwCount){intpageCount;//总页数if(rowCount>rowSize){if(rowCount%rowSize==0){pageCount=(rowCount/rowSize);}else{pageCount=(rowCount/rowSize)+1;}}else{pageCount=1;}returnpageCount;}}
解决方案五:
你不要看着多就头疼,存储过程直接复制前台页和后台把里面的列名改成自己的就可以了,很简单,100%可用我好不容易弄出来的,和你一起分享,把分都给我哦,要不然我会伤心的
解决方案六:
都给我啊
解决方案七:
问一下啊,存储过程怎么用,放在哪里?
解决方案八:
存储过程呢基本就是上面的,网上很多;至于需要绑定什么样的控件无所谓的,要理解它的原理;这样才会方便你自己的二次开发
解决方案九:
问一下啊,存储过程怎么用,放在哪里?++++++++++++++++++++++++++++++++++++++++//代码是Webmatrix生成的publicintMyInsertMethodNews(stringnews_title,stringnews_content,System.DateTimenews_time,intnews_type){//增加一条新的文章System.Data.IDbConnectiondbConnection=newSystem.Data.SqlClient.SqlConnection(connectionString);System.Data.IDbCommanddbCommand=newSystem.Data.SqlClient.SqlCommand();dbCommand.CommandType=CommandType.StoredProcedure;dbCommand.CommandText="sp_news_ADD";//存储过程dbCommand.Connection=dbConnection;System.Data.IDataParameterdbParam_news_title=newSystem.Data.SqlClient.SqlParameter();dbParam_news_title.ParameterName="@news_title";dbParam_news_title.Value=news_title;dbParam_news_title.DbType=System.Data.DbType.String;dbCommand.Parameters.Add(dbParam_news_title);System.Data.IDataParameterdbParam_news_content=newSystem.Data.SqlClient.SqlParameter();dbParam_news_content.ParameterName="@news_content";dbParam_news_content.Value=news_content;dbParam_news_content.DbType=System.Data.DbType.String;dbCommand.Parameters.Add(dbParam_news_content);System.Data.IDataParameterdbParam_news_time=newSystem.Data.SqlClient.SqlParameter();dbParam_news_time.ParameterName="@news_time";dbParam_news_time.Value=news_time;dbParam_news_time.DbType=System.Data.DbType.DateTime;dbCommand.Parameters.Add(dbParam_news_time);System.Data.IDataParameterdbParam_news_type=newSystem.Data.SqlClient.SqlParameter();dbParam_news_type.ParameterName="@news_type";dbParam_news_type.Value=news_type;dbParam_news_type.DbType=System.Data.DbType.Int32;dbCommand.Parameters.Add(dbParam_news_type);introwsAffected=0;dbConnection.Open();try{rowsAffected=dbCommand.ExecuteNonQuery();}finally{dbConnection.Close();}returnrowsAffected;}
解决方案十:
一楼说存储过程直接复制,复制到哪里啊?
解决方案十一:
在你的数据库里.在查询分析器里执行一下.
解决方案十二:
分页存储过程又无数个版本。随便用一个分页的时候gridview点页数,然后存储过程pageindex参数设成那页的页数就行很简单的。
解决方案十三:
^_^
解决方案十四:
uo
解决方案十五:
学习
解决方案:
it'sgoodidea~
解决方案:
aspnetpager很方便的
解决方案:
来此认真学习了。
解决方案:
mark
解决方案:
复制到数据库里!!!分都给1楼吧
解决方案:
学习了