没有任何反应,当我点击页面上的GridView分页 [英] Nothing happens when I click on page on GridView with paging

查看:596
本文介绍了没有任何反应,当我点击页面上的GridView分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的C#和.NET,但被困在这几天,现在,我使用MVC 3(.NET 4.0)Web应用程序。

I'm new to C# and .NET, but stuck on this for a couple days now, I am using MVC 3 (.NET 4.0) Web Application.

我通过看教程,使基于与下面的code一个SqlDataSource的GridView:

I looked through tutorials to make a GridView based on a SqlDataSource with the code below:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            OnPageIndexChanging = "GridView1_PageIndexChanging"
            AutoGenerateColumns="False" DataKeyNames="LastName,FirstName"
            EnablePersistedSelection="True" SelectedRowStyle-BackColor="Yellow" 
            DataSourceID="SqlDataSource1" AllowSorting="True" >
            <Columns>
                <asp:BoundField DataField="LastName" HeaderText="Last Name" ReadOnly="True" SortExpression="LastName" />
                <asp:BoundField DataField="FirstName" HeaderText="First Name" ReadOnly="True" SortExpression="FirstName" />
                ...
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
            SelectCommand="SELECT * FROM User WHERE [IsDeleted]=0"></asp:SqlDataSource> 

然而,当我点击不同的页面,没有任何反应(它看起来像是重新加载相同的页面),但是当我在Chrome的新标签中打开,它只是打开一个空白页,当我悬停在链接2进入第2页,这是什么所示:

However, when I click on the different pages, nothing happens(it looked like it reloaded the same page), but when I open in a new tab in Chrome, it just opens a blank page, when I hover over the link "2" to go to page 2, this is what shows:

javascript:__doPostBack('ctl00$MainContent$GridView1','Page$2') 

当我点击标题做一个排序,什么也没发生一样的网页,并链接这样说:

When I click on the title to do a sort, nothing happens just as the pages, and the link says this:

javascript:__doPostBack('ctl00$MainContent$GridView1','Sort$WindowsUsername')

我也试图把这个ASPX文件的顶部:

I've also tried putting on top of the aspx file this:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="..." %>
<script runat="server">

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
</script>

和同样的问题。该功能甚至没有被称为当我点击其他网页

And same problem. This function isn't even being called when I click on other pages

我缺少的东西的地方?任何帮助AP preciated!

Am I missing something somewhere? Any help appreciated!

推荐答案

您必须在.aspx,你没有指定 OnPageIndexChanging 事件。它应该是:

You must specify the event for OnPageIndexChanging in your .aspx, which you don't have. It should be:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        OnPageIndexChanging = "GridView1_PageIndexChanging" 
        AutoGenerateColumns="False" DataKeyNames="LastName,FirstName"
        EnablePersistedSelection="True" SelectedRowStyle-BackColor="Yellow" 
        DataSourceID="SqlDataSource1" AllowSorting="True">

这篇关于没有任何反应,当我点击页面上的GridView分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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