Asp.Net------------sqlparameter

分页列表使用
前台代码:
 
< div >
            
< asp:Repeater ID = " rptUserList "  runat = " server " >
                
< HeaderTemplate >
                    
< table >
                        
< tr >
                            
< td >
                                
< input type = " checkbox "  id = " chkAll "  runat = " server "  name = " 全选/不选 "  onclick = " checkAll(this); "   /></ td >
                            
< td >
                                用户id
</ td >
                            
< td >
                                用户名
</ td >
                            
< td >
                                用户性别
</ td >
                            
< td >
                                用户权限组
                            
</ td >
                            
< td >
                                删除状态
                            
</ td >
                            
< td >
                                删除用户
</ td >
                        
</ tr >
                
</ HeaderTemplate >
                
< ItemTemplate >
                    
< tr >
                        
< td >
                            
< asp:CheckBox ID = " chkSel "  runat = " server "   /></ td >
                        
< td >
                            
<% # Eval( " Id " %>
                        
</ td >
                        
< td >
                            
<% # Eval( " UserName " %>
                        
</ td >
                        
< td >
                            
<% # Eval( " Gender " %>
                        
</ td >
                        
< td >
                            
<% # Eval( " GroupId " %>
                        
</ td >
                        
< td >
                            
<% # Eval( " IsDelete " %>
                        
</ td >
                        
< td >
                            
< asp:ImageButton ID = " btnToWishList "  runat = " server "  AlternateText = " Move to wish list "
                                CausesValidation
= " false "  CommandArgument = ' <%# Eval("Id") %> '  CommandName = " del "
                                ImageUrl
= " ~/Comm_Images/button-wishlist.gif "   ToolTip = " Deltet sh list "   />
                        
</ td >
                    
</ tr >
                
</ ItemTemplate >
                
< FooterTemplate >
                    
</ table >
                
</ FooterTemplate >
            
</ asp:Repeater >
            
< webdiyer:AspNetPager ID = " AspNetPager2 "  runat = " server "  Width = " 100% "  UrlPaging = " True "
                SubmitButtonText
= " 跳 转 "  AlwaysShow = " True "  ShowCustomInfoSection = " Left "  NumericButtonTextFormatString = " [{0}] "
                PagingButtonSpacing
= " 4px "  SubmitButtonStyle = " border:1px solid #000000;height:20px;width:50px "
                InputBoxStyle
= " border:1px #000000 solid;text-align:center "  HorizontalAlign = " Right "
                TextAfterInputBox
= " 页  "  TextBeforeInputBox = " "  ShowInputBox = " Always "  PrevPageText = " 上一页  "
                NumericButtonCount
= " 5 "  NextPageText = "  下一页 "  FirstPageText = " 首页  "  LastPageText = "  尾页 "
                BorderColor
= " #FFFFC0 "  OnPageChanged = " AspNetPager1_PageChanged " ></ webdiyer:AspNetPager >
        
</ div >
后台代码:
 
protected   void  Page_Load( object  sender, EventArgs e)
    
{
        
if (!Page.IsPostBack)
        
{
            AspNetPager2.CurrentPageIndex 
= 1;
            AspNetPager2.PageSize 
= 3;
            BindRptUserList();
        }

    }

    
private   void  BindRptUserList()
    
{
        
int RecordCount = 0;
        
this.rptUserList.DataSource = GetUserList(AspNetPager2.CurrentPageIndex, AspNetPager2.PageSize, out RecordCount);
        
this.rptUserList.DataBind();
        AspNetPager2.RecordCount 
= RecordCount;
        Response.Write(RecordCount);
    }

    
private  DataTable GetUserList( int  pageIndex,  int  pageSize,  out   int  recordCount)
    
{
        recordCount 
= 0;
        SqlParameter[] myparams 
= new SqlParameter[]{
                
new SqlParameter("@PageIndex",SqlDbType.Int),
                
new SqlParameter("@PageSize",SqlDbType.Int),
                
new SqlParameter("@RecordCount",SqlDbType.Int)
        }
;
        myparams[
0].Value = pageIndex;
        myparams[
1].Value = pageSize;
        myparams[
2].Direction = ParameterDirection.Output;
        DataTable dt 
= SqlHelper.ExecuteTable(SqlHelper.CONN_STRING_Agriculture, CommandType.StoredProcedure, "p_User_GetUserListPager", myparams);
        
if (dt.Rows.Count > 0)
        
{
            recordCount 
= Convert.ToInt32(myparams[2].Value.ToString());
        }

        
return dt;

    }

    
protected   void  AspNetPager1_PageChanged( object  src, Wuqi.Webdiyer.PageChangedEventArgs e)
    
{
        AspNetPager2.CurrentPageIndex
=e.NewPageIndex;
    }
昨天晚上遇到一个问题: 在分页控件 返回总记录时 。总是为Null让我非常的郁闷,怎么找都找不到原因, 
最后单步 发现,问题出现在 sqlhelper 中 把
  public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
        SqlDataReader reader;
        SqlCommand cmd = new SqlCommand();
        SqlConnection conn = new SqlConnection(connectionString);
        try
        {
            PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
            SqlDataReader reader2 = cmd.ExecuteReader(CommandBehavior.CloseConnection);
           // cmd.Parameters.Clear();
            reader = reader2;
        }
        catch
        {
            conn.Close();
            throw;
        }
        return reader;
    }
总结下: 学习一样东西,不能心急,要慢慢来,才能看明白问题,只有冷静才能很好的解决问题
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值