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 RadGrid2PageIndexCh开发者_如何学Pythonanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
{
int index = e.NewPageIndex;
int current = RadGrid1.CurrentPageIndex;
}
}
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
AllowCustomPaging = True
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
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
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.
I just realized that I had both AllowPaging="true"
andAllowCustomPaging="true"
in my grid. Removing one of these fixed the issue.
精彩评论