如何防止在 UpdatePanel 中的 GridView 分页上回发 [英] How to prevent Postback on GridView paging in UpdatePanel
本文介绍了如何防止在 UpdatePanel 中的 GridView 分页上回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 UpdatePanel 中的 GridView 中应用了分页.当我前进到下一个结果集时,我的页面上会发生完整的回发.我是否需要在 web.config 文件或我的代码中做一些修改.
I have apply paging in GridView which is in UpdatePanel.When I move forward to the next result set full Postback occur on my Page.Do i need to do some modification in web.config file or in my code.
[ ASPX ]
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:GridView ID="gvCommentSample" runat="server"
OnPageIndexChanging="gvCommentSample_PageIndexChanging" AllowPaging="true" PageSize="2"
ShowFooter="false" Width="100%" ShowHeader="false" BorderWidth="0px" >
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
[ CODE BEHIND ]
Dim table As DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
bindGridView()
End If
End Sub
Private Function GetTable() As DataTable
table = New DataTable()
table.Columns.Add("FirstName")
table.Columns.Add("LastName")
Dim row As DataRow = table.NewRow()
row("FirstName") = "John"
row("LastName") = "Johnoson"
table.Rows.Add(row)
row = table.NewRow()
row("FirstName") = "Johnny"
row("LastName") = "Marley"
table.Rows.Add(row)
row = table.NewRow()
row("FirstName") = "Kate"
row("LastName") = "Li"
table.Rows.Add(row)
Return table
End Function
Public Sub bindGridView()
gvCommentSample.DataSource = GetTable()
gvCommentSample.DataBind()
End Sub
Protected Sub gvCommentSample_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
Dim gvCommentSample As GridView = DirectCast(sender, GridView)
gvCommentSample.PageIndex = e.NewPageIndex
gvCommentSample.DataSource = GetTable()
gvCommentSample.DataBind()
End Sub
推荐答案
我得到了解决方案.我必须把
I got the solution. I have to put
<xhtmlConformance mode="Transitional"/>
web.Config 文件中的元素.
element in web.Config file.
这篇关于如何防止在 UpdatePanel 中的 GridView 分页上回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文