-1

我在 asp.net 中搜索分页示例,通过它我可以为我的项目在线考试制定解决方案,用户可以导航到下一个和上一个问题,并且他/她可以直接移动到特定问题。我用谷歌搜索了这个查询,并使用 gridview 获得了解决方案分页。建议和示例链接将不胜感激,谢谢!

更新

 <asp:GridView ID="gvUserlist" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            DataKeyNames="Login_Id" DataSourceID="DSUserList" CellPadding="4" ForeColor="#333333"
            GridLines="None" Width="681px">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>

                <asp:BoundField DataField="Login_Id" HeaderText="User Id" ReadOnly="True" SortExpression="Login_Id" />
                <asp:BoundField DataField="User_Type" HeaderText="User Type" SortExpression="User_Type" />
                <asp:BoundField DataField="First_Name" HeaderText="First Name" SortExpression="First_Name" />
                <asp:BoundField DataField="Last_Name" HeaderText="Last Name" SortExpression="Last_Name" />
                <asp:TemplateField>
                    <EditItemTemplate>
                        <asp:CheckBox ID="cbuserid" runat="server" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="cbuserid" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        <asp:SqlDataSource ID="DSUserList" runat="server" ConnectionString="<%$ ConnectionStrings:JPConnString %>"
            SelectCommand="SELECT User_Login.Login_Id, User_Login.User_Type, User_Login.Login_Status, derivedtbl_1.First_Name, derivedtbl_1.Last_Name FROM User_Login INNER JOIN (SELECT Email_Id, First_Name, Last_Name FROM User_Info UNION SELECT Email_Id, First_Name, Last_Name FROM Emp_Info) AS derivedtbl_1 ON User_Login.Login_Id = derivedtbl_1.Email_Id WHERE (User_Login.Login_Status = @Login_Status)">
            <SelectParameters>
                <asp:Parameter DefaultValue="Activate" Name="Login_Status" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>

正如我之前提到的,我需要在线考试的分页,用户可以在其中导航到下一个并预览,并且数据将按列而不是按行显示。据我所知,网格视图按行显示数据。

因为,在在线考试系统中,我必须不以表格形式显示该数据,我只需要移动到表格的下一行。我不这么认为,grid-view 将帮助我解决这个问题,因为它以表格形式显示数据

4

2 回答 2

0

威震天。我通常不会为某人写出整个代码,但我今天感觉特别慷慨。

这是我在项目中使用的 VB 寻呼机。这是我在 MVC 应用程序中使用的辅助方法。

    ''' <summary>
    ''' Pagers the specified helper.
    ''' </summary>
    ''' <param name="helper">The helper.</param>
    ''' <param name="urlPrefix">The URL prefix.</param>
    ''' <param name="totalRecords">The total records.</param>
    ''' <param name="currentPage">The current page.</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Extension()>
    Public Function Pager(helper As HtmlHelper,
                          urlPrefix As String,
                          totalRecords As Integer,
                          currentPage As Integer) As MvcHtmlString

        ' Get out if we have 5 or less records
        If totalRecords <= 5 Then Return Nothing

        ' Make sure we're not getting invalid pages
        If currentPage <= 0 Then currentPage = 1

        ' Setup our initial variables
        Dim sb1 As New StringBuilder(),
            totalPages = (Math.Round((totalRecords / 5) + 0.5)),
            startingPoint,
            linksAfterCurrent,
            endPoint,
            i


        ' Set boundries for inner link numbers
        Select Case currentPage
            Case totalPages : startingPoint = currentPage - 5
            Case (totalPages - 1) : startingPoint = currentPage - 4
            Case Else : startingPoint = currentPage - 3
        End Select

        Select Case currentPage
            Case 1 : linksAfterCurrent = currentPage + 4
            Case 2 : linksAfterCurrent = currentPage + 3
            Case Else : linksAfterCurrent = currentPage + 2
        End Select

        sb1.Append("<div id=""pagercontainer""><ul class=""pager"">")

        ' Display the previous button and first button
        If currentPage > 1 AndAlso startingPoint >= 1 Then
            If startingPoint > 1 Then sb1.AppendLine([String].Format("<li><a href=""{0}{1}"" title=""go to page {1}"">&laquo;</a></li>", urlPrefix, currentPage - 1))
            sb1.AppendLine([String].Format("<li><a href=""{0}1"" title=""go to page 1"">1</a></li>", urlPrefix))
            If startingPoint > 1 Then sb1.AppendLine("&nbsp;&nbsp;&nbsp;")
        End If


        ' Generate the inner numbers
        i = startingPoint
        While (i < linksAfterCurrent)

            ' This 'if' statement keeps us from building a pager list that's longer than the totalPages.
            If (i >= 0) AndAlso
                (i < totalPages) Then

                ' Build out the inner pager buttons
                sb1.AppendLine([String].Format("<li><a href=""{0}{1}"" {2} title=""go to page {1}"">{1}</a></li>",
                                                urlPrefix,
                                                i + 1,
                                                If(i + 1 = currentPage, "class=""youarehere""", String.Empty)))
            End If

            i += 1
        End While

        endPoint = i

        ' Display the next button and the last button
        If (currentPage < endPoint) AndAlso
            (endPoint < totalPages) Then
            If endPoint < totalPages - 1 Then sb1.AppendLine("&nbsp;&nbsp;&nbsp;")
            sb1.AppendLine([String].Format("<li><a href=""{0}{1}"" title=""go to page {1}"">{1}</a></li>", urlPrefix, totalPages.ToString()))
            If endPoint < totalPages - 1 Then sb1.AppendLine([String].Format("<li><a href=""{0}{1}"" title=""go to page {1}"">&raquo;</a></li>", urlPrefix, currentPage + 1))
        End If


        sb1.Append("</ul></div><div class=""clear""></div>")


        Return MvcHtmlString.Create(sb1.ToString())
    End Function

    ''' <summary>
    ''' Pagers the specified helper.
    ''' </summary>
    ''' <param name="helper">The helper.</param>
    ''' <param name="urlPrefix">The URL prefix.</param>
    ''' <param name="totalRecords">The total records.</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Extension()>
    Public Function Pager(helper As HtmlHelper,
                          urlPrefix As String,
                          totalRecords As Integer) As MvcHtmlString
        Return helper.Pager(urlPrefix, totalRecords, 1)
    End Function

这就是我如何使用它

    @Html.Pager("?page=", Model.TotalEvents, Model.PageNumber)
于 2012-07-26T16:10:08.117 回答
0

听起来是您的DetailsView完美选择。它旨在显示单个元素,但您仍然可以将其绑定到元素列表并向前和向后导航。

于 2012-07-26T16:03:44.450 回答