从服务器端绑定数据时 Telerik Radgrid 中的分页问题
我有两个 radgrid ,对于第一个 radgrid,我从服务器端绑定数据,对于第二个 radgrid,我从客户端通过 sqldatasource 绑定数据。 我通过客户端绑定数据的radgrid2,分页属性工作正常,并且我的网格每次都会刷新。 但主要问题是,当从服务器端绑定 radgrid 时,我的分页属性不起作用,当我从服务器端绑定数据时,我是否必须设置它们的任何属性才能使分页工作,任何人都可以帮助解决这个问题。
这是我的 aspx 页面代码,其中包含 radgrid
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadGridRefreshTest.aspx.cs" Inherits="RadGridTest.RadGridRefreshTest" enableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true">
</telerik:RadScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" AllowCustomPaging="True" onpageindexchanged="RadGrid1PageIndexChanged" >
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
second grid
<telerik:RadGrid ID="RadGrid2" runat="server" CellSpacing="0"
DataSourceID="SqlDataSource" GridLines="None"
onpageindexchanged="RadGrid2PageIndexChanged" >
<MasterTableView AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource" AllowPaging="true" PageSize="10" >
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="CustomerID"
FilterControlAltText="Filter CustomerID column" HeaderText="CustomerID"
ReadOnly="True" SortExpression="CustomerID" UniqueName="CustomerID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CompanyName"
FilterControlAltText="Filter CompanyName column" HeaderText="CompanyName"
SortExpression="CompanyName" UniqueName="CompanyName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ContactName"
FilterControlAltText="Filter ContactName column" HeaderText="ContactName"
SortExpression="ContactName" UniqueName="ContactName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ContactTitle"
FilterControlAltText="Filter ContactTitle column" HeaderText="ContactTitle"
SortExpression="ContactTitle" UniqueName="ContactTitle">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Address"
FilterControlAltText="Filter Address column" HeaderText="Address"
SortExpression="Address" UniqueName="Address">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="City"
FilterControlAltText="Filter City column" HeaderText="City"
SortExpression="City" UniqueName="City">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Region"
FilterControlAltText="Filter Region column" HeaderText="Region"
SortExpression="Region" UniqueName="Region">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PostalCode"
FilterControlAltText="Filter PostalCode column" HeaderText="PostalCode"
SortExpression="PostalCode" UniqueName="PostalCode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Country"
FilterControlAltText="Filter Country column" HeaderText="Country"
SortExpression="Country" UniqueName="Country">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Phone"
FilterControlAltText="Filter Phone column" HeaderText="Phone"
SortExpression="Phone" UniqueName="Phone">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Fax"
FilterControlAltText="Filter Fax column" HeaderText="Fax" SortExpression="Fax"
UniqueName="Fax">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
<FilterMenu EnableImageSprites="False"></FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>"
SelectCommand="SELECT * FROM [Customers]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
这是文件背后的代码,我在其中编写使用数据源进行网格绑定的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
using Telerik.Web.UI;
using Telerik.Web.Data;
namespace RadGridTest
{
public partial class RadGridRefreshTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString ="data source=ADMIN-PC1;uid=sa;password=sql;database=NorthWind";
DataSet ds = new DataSet("CustOrders");
SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM Customers", con);
da1.TableMappings.Add("Table", "Customers");
da1.Fill(ds);
RadGrid1.DataSource = ds;
RadGrid1.DataBind();
}
protected void RadGrid1PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
{
int index = e.NewPageIndex;
int current = RadGrid1.CurrentPageIndex;
}
protected void RadGrid2PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
{
int index = e.NewPageIndex;
int current = RadGrid1.CurrentPageIndex;
}
}
I have two radgrid , for the first radgrid i am binding the data from serverside , and for the second radgrid i am binding the data through sqldatasource from clientside.
The radgrid2 for which i bind the data through clientside,pagination property works fine , and my grid gets refresh each time.
But the major problem is when bind the radgrid from serverside my pagination property is not working,is their any property i have to set for pagination to work when i am binding the data from serverside, can any one please help to figure out the problem.
This is my aspx page code which contains the radgrid
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadGridRefreshTest.aspx.cs" Inherits="RadGridTest.RadGridRefreshTest" enableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true">
</telerik:RadScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" AllowCustomPaging="True" onpageindexchanged="RadGrid1PageIndexChanged" >
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
second grid
<telerik:RadGrid ID="RadGrid2" runat="server" CellSpacing="0"
DataSourceID="SqlDataSource" GridLines="None"
onpageindexchanged="RadGrid2PageIndexChanged" >
<MasterTableView AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource" AllowPaging="true" PageSize="10" >
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="CustomerID"
FilterControlAltText="Filter CustomerID column" HeaderText="CustomerID"
ReadOnly="True" SortExpression="CustomerID" UniqueName="CustomerID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CompanyName"
FilterControlAltText="Filter CompanyName column" HeaderText="CompanyName"
SortExpression="CompanyName" UniqueName="CompanyName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ContactName"
FilterControlAltText="Filter ContactName column" HeaderText="ContactName"
SortExpression="ContactName" UniqueName="ContactName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ContactTitle"
FilterControlAltText="Filter ContactTitle column" HeaderText="ContactTitle"
SortExpression="ContactTitle" UniqueName="ContactTitle">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Address"
FilterControlAltText="Filter Address column" HeaderText="Address"
SortExpression="Address" UniqueName="Address">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="City"
FilterControlAltText="Filter City column" HeaderText="City"
SortExpression="City" UniqueName="City">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Region"
FilterControlAltText="Filter Region column" HeaderText="Region"
SortExpression="Region" UniqueName="Region">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PostalCode"
FilterControlAltText="Filter PostalCode column" HeaderText="PostalCode"
SortExpression="PostalCode" UniqueName="PostalCode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Country"
FilterControlAltText="Filter Country column" HeaderText="Country"
SortExpression="Country" UniqueName="Country">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Phone"
FilterControlAltText="Filter Phone column" HeaderText="Phone"
SortExpression="Phone" UniqueName="Phone">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Fax"
FilterControlAltText="Filter Fax column" HeaderText="Fax" SortExpression="Fax"
UniqueName="Fax">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
<FilterMenu EnableImageSprites="False"></FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>"
SelectCommand="SELECT * FROM [Customers]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
This is the code behind file where i am writing the code for grid binding using datasource
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
using Telerik.Web.UI;
using Telerik.Web.Data;
namespace RadGridTest
{
public partial class RadGridRefreshTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString ="data source=ADMIN-PC1;uid=sa;password=sql;database=NorthWind";
DataSet ds = new DataSet("CustOrders");
SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM Customers", con);
da1.TableMappings.Add("Table", "Customers");
da1.Fill(ds);
RadGrid1.DataSource = ds;
RadGrid1.DataBind();
}
protected void RadGrid1PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
{
int index = e.NewPageIndex;
int current = RadGrid1.CurrentPageIndex;
}
protected void RadGrid2PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
{
int index = e.NewPageIndex;
int current = RadGrid1.CurrentPageIndex;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在将 RadGrid.DataSource 设置为 Linq 查询时遇到了类似的问题。我会告诉你一些我尝试过的事情,以及我最终不得不采取的行动。
首先,如果
那么默认分页将被覆盖。尝试将AllowPaging 设置为true,或将AllowCustomPaging 设置为true,但不能同时设置两者。 Telerik 的控制变化无常! :)
我也尝试在 MasterTableView 内部设置分页,但无济于事
我还添加了AllowViewstate 并确保该控件已链接到RadAjaxManager
两者都对我不起作用,但请尝试一下。
我最终使用了列表视图并为内部数据设置了模板化列,并启用了分页,一切都工作得很好。我知道这不是一个直接的答案,但也许它会给你一些新的想法。
I had a similar problem setting the RadGrid.DataSource to a Linq query. I'll tell you a few of the things I tried, and what I eventually had to move to.
First off, if
Then the default paging is overridden. Try setting either the AllowPaging to true, or AllowCustomPaging to true, but not both. Telerik controls are fickle! :)
I tried setting up paging inside of the MasterTableView as well, to no avail
I also added AllowViewstate and made sure the control was linked to the RadAjaxManager
Neither worked for me, but give it a shot.
I eventually used a Listview and setup the templated columns for the data inside, and enabled paging and it all worked just fine. I know this isn't a direct answer, but maybe it will give you some new ideas.
我刚刚意识到我的网格中有
AllowPaging="true"
和AllowCustomPaging="true"
。删除其中之一即可解决该问题。I just realized that I had both
AllowPaging="true"
andAllowCustomPaging="true"
in my grid. Removing one of these fixed the issue.