我有两个radgrid,对于第一个radgrid,我绑定来自serverside的数据,而对于第二个radgrid,我通过sqldatasource从clientside绑定数据。 我通过clientside绑定数据的radgrid2,pagination属性工作正常,我的网格每次都刷新。 但是主要的问题是当从服务器端绑定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;
}
}
答案 0 :(得分:7)
我有一个类似的问题,将RadGrid.DataSource设置为Linq查询。我会告诉你一些我尝试过的事情,以及我最终要做的事情。
首先,如果
AllowCustomPaging = True
然后覆盖默认分页。尝试将AllowPaging设置为true,或将AllowCustomPaging设置为true,但不能同时设置为true。 Telerik控件变幻莫测! :)
我也尝试在MasterTableView中设置分页,但无济于事 我还添加了AllowViewstate并确保控件已链接到RadAjaxManager
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
对我来说都没有用,但试一试。
我最终使用了Listview并为内部数据设置了模板化列,并且启用了分页,这一切都运行得很好。我知道这不是一个直接的答案,但它可能会给你一些新的想法。
答案 1 :(得分:1)
我刚刚意识到我的网格中有AllowPaging="true"
和AllowCustomPaging="true"
。删除其中一个修复了该问题。