我想在数据列表plz中使用分页,请参阅我的代码,然后告诉我如何在其中使用分页? [英] i want to use paging in datalist plz see my code thn tell me how to use paging in that?

查看:80
本文介绍了我想在数据列表plz中使用分页,请参阅我的代码,然后告诉我如何在其中使用分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其ASPX页面

<asp:DataList ID="dl" runat="server" RepeatDirection="Horizontal"

                            DataKeyField="ID" RepeatColumns="5">
                        <HeaderTemplate>

                        </HeaderTemplate>
                        <ItemTemplate>
                         <table>
                        <tr>
                        <td>
                            <%--<asp:ImageButton ID="ibtn" runat="server"  Width="100px" Height="100px"
                                ImageUrl='<%#DataBinder.Eval(Container.DataItem,"Recipe_Path")%>'
                                onclick="ibtn_Click" oncommand="ibtn_Command"/>--%>
                            <asp:Image ID="Image2" runat="server" ImageUrl='<%#DataBinder.Eval(Container.DataItem,"Recipe_Path")%>' Width="150px" Height="150px" />
                        </td>
                        </tr>
                        <%--<td>
                           ImageUrl='<%#DataBinder.Eval(Container.DataItem,"Image_Family")%>'
                                onclick="ibtn_Click" oncommand="ibtn_Command"/>
                        </td>--%>
                        <tr>
                        <td>
                            <asp:LinkButton ID="lbtnimage" runat="server"

                                CommandArgument='<%#Bind("ID") %>' Text='<%# Eval("Title_Recipes") %>'

                                onclick="lbtnimage_Click" oncommand="lbtnimage_Command">LinkButton</asp:LinkButton>
                        </td>
                        </tr>
                         </table>
                        </ItemTemplate>
                        <FooterTemplate>

                        </FooterTemplate>
                        </asp:DataList>


现在,cs页面的编码:>
connection();
OleDbDataAdapter da =新的OleDbDataAdapter(从addrecipes中选择*,其中Active =" Active由ID desc排序",con);
DataSet ds = new DataSet();
da.Fill(ds,"addrecipes");
dl.DataSource = ds;
dl.DataBind();



想要在此页面上使用分页请帮助我


Now the coding of the cs page:>
connection();
OleDbDataAdapter da = new OleDbDataAdapter("select * from addrecipes where Active=''Active'' order by ID desc", con);
DataSet ds = new DataSet();
da.Fill(ds, "addrecipes");
dl.DataSource = ds;
dl.DataBind();



want to use paging at this page plz help me

推荐答案

try:
try:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%


ConnectionStrings:ConnString %> ' SelectCommand =" 选择x,y,z ..." < tr > < td > < asp:Label ID =" runat 服务器" 可见 true" < /td > < /tr > < tr > < td =" center" < asp:Button ID =" runat 服务器" 文本 <<" OnClick =" > < asp:Button ID =" runat 服务器" 文本 >>" OnClick =" >
ConnectionStrings:ConnString %>'SelectCommand="SELECT x,y,z ..."> <tr> <td> <asp:Label ID="lblCurrentPage" runat="server" Visible="true"> </td> </tr> <tr> <td align="center"> <asp:Button ID="cmdPrev" runat="server" Text=" << " OnClick="cmdPrev_Click"> <asp:Button ID="cmdNext" runat="server" Text=" >> " OnClick="cmdNext_Click">



并在后面的代码中:



and in the code behind:

public int CurrentPage
   {
       get
       {

           object o = this.ViewState["_CurrentPage"];
           if (o == null)
               return 0;
           else
               return (int)o;
       }
       set
       {
           this.ViewState["_CurrentPage"] = value;
       }

   }







 protected void items()
    {
        PagedDataSource objDs = new PagedDataSource();
        DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        objDs.DataSource = dv;
        objDs.AllowPaging = true;
        objDs.PageSize = 20;
        objDs.CurrentPageIndex = CurrentPage;
        lblCurrentPage.Text = "Page:" + (CurrentPage + 1).ToString() + " Of " + objDs.PageCount.ToString();
        cmdPrev.Enabled = !objDs.IsFirstPage;
        cmdNext.Enabled = !objDs.IsLastPage;
        DataList1.DataSource = objDs;
       DataList1.DataBind();
 
    }
 
 
protected void cmdPrev_Click(object sender, EventArgs e)
    {
        try
        {
            CurrentPage -= 1;
            items();
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
        }
    }
 
    protected void cmdNext_Click(object sender, EventArgs e)
    {
        try
        {
 
            CurrentPage += 1;
            items();
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
        }
    }



您也可以使用Dataset对象来代替DataView.

或查看以下网址: http://forums.asp.net/t/1108198.aspx [ ^ ]



In place of DataView u can also use Dataset object too.

or check at:http://forums.asp.net/t/1108198.aspx[^]


Check this[^]

it''ll be helpful for you


这篇关于我想在数据列表plz中使用分页,请参阅我的代码,然后告诉我如何在其中使用分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆