<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
    DataFile="~/NJUTDW.mdb" SelectCommand="SELECT top 7 * FROM [news] WHERE ([classid] = ?) ORDER BY [addtime] DESC">
    <SelectParameters>
        <asp:Parameter DefaultValue="8" Name="classid" Type="Int32" />
    </SelectParameters>
</asp:AccessDataSource>
这个sql怎么把符合classid的全取出来了啊,我用repeater呈现的~~

解决方案 »

  1.   

    好像也不是全取出来了,如果共有10 个结果,我select top 9 ,8,…………都会取9 个,而select top 10 时就全取出来了~~纠结啊~~
      

  2.   

    SELECT  * FROM [news] WHERE ([classid] = ?) ORDER BY [addtime] DESC
    这样不行吗?楼主啥意思
      

  3.   

     "SELECT TOP 7 * FROM [news] WHERE [classid]="+classid+"ORDER BY [addtime] DESC"
      

  4.   

    再把repeater控件代码贴出来看看吧~
     <asp:Repeater ID="Repeater1" runat="server" DataSourceID="AccessDataSource1" >
        <ItemTemplate >
        <table class="fixedTable" width="323">
                        <tr>
                            <td width="10">
                                <asp:Image ID="Image1" runat="server" ImageUrl="../pic/news_icon.gif" />
                            </td>
                            <td width="273">
                                <asp:HyperLink ID="HyperLink1" runat="server" Font-Names="宋体"   Font-Size="Small"  Font-Underline="False" ToolTip ='<%#eval("title") %>' NavigateUrl='<%# "../detailview.aspx?id=" & container.dataitem("id").toString %>'
                                    Text='<%#  iif(Eval("title").length>19,left(eval("title"),19) & "…",eval("title")) %>'></asp:HyperLink>
                            </td>
                            <td width="90">
                                [<asp:Label ID="Label1" runat="server" Text='<%# Eval("addtime", "{0:d}") %>'></asp:Label>
                                ]</td>
                        </tr>
                    </table>
        
        </ItemTemplate>
        </asp:Repeater>
      

  5.   

    ASP.net不是有自带封装好了的分页功能吗,只要你开启分页他就会有每页显示多少条和当前显示几页的功能
      

  6.   


    我看我的accessdatasource,还有repeater 都没有分页的属性啊?
      

  7.   

    在页面加 <asp:LinkButton ID="btnFirst" runat="server" OnClick ="btnFirst_Click">第一页</asp:LinkButton>&nbsp;
                            <asp:LinkButton ID="btnPrevious" runat="server" OnClick ="btnPrevious_Click">上一页</asp:LinkButton>&nbsp;
                            (<asp:Label ID="lblPageIndex" runat="server" Text="Label"></asp:Label>/<asp:Label ID="lblPageCount"
                                runat="server" Text="Label"></asp:Label>)&nbsp;
                            <asp:LinkButton ID="btnNext" runat="server" OnClick ="btnNext_Click">下一页</asp:LinkButton>&nbsp;
                            <asp:LinkButton ID="btnLast" runat="server" OnClick ="btnLast_Click">最后一页</asp:LinkButton>在后台加protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pds.AllowPaging = true;//允许分页
                pds.CurrentPageIndex = 0;//当前页的索引设置为0,即第一页的索引为0
                pds.PageSize = 4;//单页显示的项数        }
            RefreshStatus();    }
        private void RefreshStatus()
        {
            DataView dv = (DataView)AccessDataSource1.Select(DataSourceSelectArguments.Empty);
            pds.DataSource =dv ;
            DataList1.DataSource = pds;
            DataList1.DataBind();        btnFirst.Enabled = !pds.IsFirstPage;//判断当前页是不是第一页,如果是,那么"第一页"的按钮就应该不可用
            btnPrevious.Enabled = !pds.IsFirstPage;//判断当前页是不是第一页,如果是,那么"上一页"的按钮就应该不可用
            btnNext.Enabled = !pds.IsLastPage;
            btnLast.Enabled = !pds.IsLastPage;
            lblPageIndex.Text = Convert.ToString(pds.CurrentPageIndex + 1);//如果当前页是第一页,pds.CurrentPageIndex的值会为0,所以要+1
            lblPageCount.Text = pds.PageCount.ToString();
        }    protected void btnFirst_Click(object sender, EventArgs e)
        {
            pds.CurrentPageIndex = 0;//如果是第一页,就把pds.CurrentPageIndex参数设置为0,然后在绑定
            RefreshStatus();
        }    protected void btnLast_Click(object sender, EventArgs e)
        {
            pds.CurrentPageIndex = pds.PageCount - 1;
            RefreshStatus();
        }    protected void btnNext_Click(object sender, EventArgs e)
        {
            pds.CurrentPageIndex += 1;
            RefreshStatus();
        }    protected void btnPrevious_Click(object sender, EventArgs e)
        {
            pds.CurrentPageIndex -= 1;
            RefreshStatus();
        }
    就实现分页了
      

  8.   


    ..........
    楼主好样的。 还有这么取数据的啊。两种方式, 一种,存储过程分页。 每次穿当前页和每页显示多少条。直接返回给你数据。2.使用GridView 这个控件自带分页。 你的数据源 直接 select * 就行。repeater没有分页,
    想要不用存储过程,又要用repeater 就只能在itemdatabound事件去写去了
      

  9.   

    我估计不是repeater的问题,因为我用gridview试了下,也是这个状况,但accessdatasource哪里出了问题呢~~!!
      

  10.   

    抱歉各位,浪费大家时间了,我终于找到问题的结症了:并不是分页的问题.而是我的排序问题,我用 order by addtime 排序,而数据很多都是同一时间添加的,所以一并被显示了,所以可以看出accessdatasource的数据筛选顺序:先select top X (根据order by 的字段),所以有重复,再排序。 解决这个问题,可以在 order by 后再加个 限制字段,如“ordby addtime,order by id”这样就可以选出唯一的字段了,我不懂sql,也希望能帮到在此类问题纠结的同胞~~没有什么分,谢谢大家了~~