Hy,
I'm currently working on a webproject for one of our clients and I'm experiencing a strange problem with paging on the RadGrid. Hope someone will be able to help me.
I'm using a RadGrid to show some DB related data wich I have put into a DataTable before filling the RadGrid. When I fill the RadGrid I see the exact amount of rows and I see a certain number of pages at the bottom of my grid. When I click on the next page arrow, I can actually go to the page 2, so far so good. But when I click the next page again (to go to page 3 in this case), nothing happens.
I can navigate between page 1 and 2 without a problem, but I can't get any further.
For your Info I downloaded and installed the latest release and modified my Web.config to use the latest version.
You can find my code below. Fyi, this is the code of the usercontrol that contains the RadGrid. I have no Scriptmanager on the control, since I need to be able to add multiple custom controls to one page, so I added the Scriptmanager to the page. So I do infact have a Scriptmanager present.
Control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ARTravelList.ascx.cs" Inherits="Website.Controls.ARTravelList" %>
<telerik:RadAjaxManager ID="ajaxManager" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="grdTravels">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="grdTravels" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<div id="pageColorHeader">
<div class="colorHeaderText">REISOVERZICHT GROEPEN</div>
<div id="colorHeaderSub">NIEUW</div>
</div>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<telerik:RadGrid ID="grdTravels" runat="server" OnItemDataBound="grdTravel_ItemDataBound" OnItemCommand="grdTravel_ItemCommand" AutoGenerateColumns="false" AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false" AllowMultiRowEdit ="false" AllowMultiRowSelection="false" Skin="Hay" AllowPaging="true" AllowSorting="true" OnNeedDataSource="grdTravel_NeedDataSource" PageSize="50">
<MasterTableView DataKeyNames="Id" NoMasterRecordsText="Er zijn geen reizen gevonden van dit type">
<ExpandCollapseColumn Visible="False">
<HeaderStyle Width="19px"></HeaderStyle>
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False" >
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<Columns>
<telerik:GridBoundColumn Visible="False" ReadOnly="True" UniqueName="Id" DataField="Id">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Bestemming" UniqueName="Destination" DataField="Destination">
</telerik:GridBoundColumn>
<%-- <telerik:GridBoundColumn HeaderText="Beschrijving" UniqueName="Description" DataField="Description">
</telerik:GridBoundColumn> --%>
<telerik:GridTemplateColumn HeaderText="Beschrijving" UniqueName="Description">
<ItemTemplate>
<asp:HyperLink ID="lnkDescription" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn HeaderText="Heen" UniqueName="DepartureDate" DataType=System.DateTime DataFormatString="{0:dd/MM/yy}" DataField="DepartureDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Terug" UniqueName="ReturnDate" DataType=System.DateTime DataFormatString="{0:dd/MM/yy}" DataField="ReturnDate">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Niveau" UniqueName="NiveauIMG" DataField="Niveau.Grade">
<ItemTemplate>
<asp:Image ID="imgNiveau" runat="server" AlternateText="stapper" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<PagerStyle PagerTextFormat="{4} Huidige pagina {0} van {1}, items {2} tot {3} van {5}"/>
<ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
</ClientSettings>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
Code Behind
public partial class ARTravelList : ControlBase
{
private string _TravelType;
public string TravelType
{
get { return _TravelType; }
set { _TravelType = value; }
}
public string PreviousTravelType
{
get { return (Session["TravelType"] == null) ? null : (string)Session["TravelType"]; }
set { Session["TravelType"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PreviousTravelType = Request.QueryString["ReisType"].ToString();
}
}
protected void grdTravel_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
grdTravels.DataSource =GetAllTravels() ;
}
protected void grdTravel_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
DataRowView dvTravel = e.Item.DataItem as DataRowView;
HyperLink lnkDescription = e.Item.FindControl("lnkDescription") as HyperLink;
if (lnkDescription == null) return;
if (lnkDescription != null)
{
lnkDescription.NavigateUrl = "~/nl/ReisDetail/" + _TravelType + "/" + dvTravel["TravelId"] + ".aspx";// "mailto:" + dvInsurance["Email"].ToString();
lnkDescription.Text = dvTravel["Description"].ToString();
}
Image imgNiveau = e.Item.FindControl("imgNiveau") as Image;
if (imgNiveau == null) return;
if (imgNiveau != null)
{
imgNiveau.ImageUrl = dvTravel["Niveau"].ToString();
}
}
}
protected void grdTravel_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "RowClick" && e.Item is GridDataItem)
{
string url = string.Empty;
DataRowView oRow = (DataRowView)e.Item.DataItem;
string TravelId = oRow["TravelId"].ToString();
if (TravelType == "Default")
TravelType = PreviousTravelType;
url = UrlHelper.Instance.GetSiteUrl() + "/nl/ReisDetail/" +
TravelType + "/" + TravelId + ".aspx";
Response.Redirect(url);
}
}
private DataTable GetAllTravels()
{
return CreateDataTableFromList(GetTravel());
}
private DataTable CreateDataTableFromList(List<ARTravel> List)
{
DataTable oTable = new DataTable();
oTable.Columns.Add("Id", typeof(Int32));
oTable.Columns.Add("TravelId");
oTable.Columns.Add("Destination");
oTable.Columns.Add("Description");
oTable.Columns.Add("DepartureDate");
oTable.Columns.Add("ReturnDate");
oTable.Columns.Add("Niveau");
foreach (ARTravel oItem in List)
{
DataRow oRow = oTable.NewRow();
oRow["Id"] = oItem.Id;
oRow["TravelId"] = oItem.TravelId;
oRow["Destination"] = oItem.Destination.Name;
oRow["Description"] = oItem.Description;
oRow["DepartureDate"] = oItem.DepartureDate.ToShortDateString();
oRow["ReturnDate"] = oItem.ReturnDate.ToShortDateString();
oRow["Niveau"] = UrlHelper.Instance.GetSiteUrl() + "/img/ventjes" + oItem.Niveau.Grade + ".gif";
oTable.Rows.Add(oRow);
}
return oTable;
}
private List<ARTravel> GetTravel()
{
TravelType = Request.QueryString["ReisType"];
if (TravelType == "Default")
TravelType = PreviousTravelType;
ARTravel graph = new ARTravel(new ARNiveau(), new ARType(TravelType),new ARDestination());
List<ARTravel> reizen = TravelFacade.Instance.GetTravels(true,TravelType, graph);
return reizen;
}
}
I'm currently working on a webproject for one of our clients and I'm experiencing a strange problem with paging on the RadGrid. Hope someone will be able to help me.
I'm using a RadGrid to show some DB related data wich I have put into a DataTable before filling the RadGrid. When I fill the RadGrid I see the exact amount of rows and I see a certain number of pages at the bottom of my grid. When I click on the next page arrow, I can actually go to the page 2, so far so good. But when I click the next page again (to go to page 3 in this case), nothing happens.
I can navigate between page 1 and 2 without a problem, but I can't get any further.
For your Info I downloaded and installed the latest release and modified my Web.config to use the latest version.
You can find my code below. Fyi, this is the code of the usercontrol that contains the RadGrid. I have no Scriptmanager on the control, since I need to be able to add multiple custom controls to one page, so I added the Scriptmanager to the page. So I do infact have a Scriptmanager present.
Control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ARTravelList.ascx.cs" Inherits="Website.Controls.ARTravelList" %>
<telerik:RadAjaxManager ID="ajaxManager" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="grdTravels">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="grdTravels" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<div id="pageColorHeader">
<div class="colorHeaderText">REISOVERZICHT GROEPEN</div>
<div id="colorHeaderSub">NIEUW</div>
</div>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<telerik:RadGrid ID="grdTravels" runat="server" OnItemDataBound="grdTravel_ItemDataBound" OnItemCommand="grdTravel_ItemCommand" AutoGenerateColumns="false" AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false" AllowMultiRowEdit ="false" AllowMultiRowSelection="false" Skin="Hay" AllowPaging="true" AllowSorting="true" OnNeedDataSource="grdTravel_NeedDataSource" PageSize="50">
<MasterTableView DataKeyNames="Id" NoMasterRecordsText="Er zijn geen reizen gevonden van dit type">
<ExpandCollapseColumn Visible="False">
<HeaderStyle Width="19px"></HeaderStyle>
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False" >
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<Columns>
<telerik:GridBoundColumn Visible="False" ReadOnly="True" UniqueName="Id" DataField="Id">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Bestemming" UniqueName="Destination" DataField="Destination">
</telerik:GridBoundColumn>
<%-- <telerik:GridBoundColumn HeaderText="Beschrijving" UniqueName="Description" DataField="Description">
</telerik:GridBoundColumn> --%>
<telerik:GridTemplateColumn HeaderText="Beschrijving" UniqueName="Description">
<ItemTemplate>
<asp:HyperLink ID="lnkDescription" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn HeaderText="Heen" UniqueName="DepartureDate" DataType=System.DateTime DataFormatString="{0:dd/MM/yy}" DataField="DepartureDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Terug" UniqueName="ReturnDate" DataType=System.DateTime DataFormatString="{0:dd/MM/yy}" DataField="ReturnDate">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Niveau" UniqueName="NiveauIMG" DataField="Niveau.Grade">
<ItemTemplate>
<asp:Image ID="imgNiveau" runat="server" AlternateText="stapper" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<PagerStyle PagerTextFormat="{4} Huidige pagina {0} van {1}, items {2} tot {3} van {5}"/>
<ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
</ClientSettings>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
Code Behind
public partial class ARTravelList : ControlBase
{
private string _TravelType;
public string TravelType
{
get { return _TravelType; }
set { _TravelType = value; }
}
public string PreviousTravelType
{
get { return (Session["TravelType"] == null) ? null : (string)Session["TravelType"]; }
set { Session["TravelType"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PreviousTravelType = Request.QueryString["ReisType"].ToString();
}
}
protected void grdTravel_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
grdTravels.DataSource =GetAllTravels() ;
}
protected void grdTravel_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
DataRowView dvTravel = e.Item.DataItem as DataRowView;
HyperLink lnkDescription = e.Item.FindControl("lnkDescription") as HyperLink;
if (lnkDescription == null) return;
if (lnkDescription != null)
{
lnkDescription.NavigateUrl = "~/nl/ReisDetail/" + _TravelType + "/" + dvTravel["TravelId"] + ".aspx";// "mailto:" + dvInsurance["Email"].ToString();
lnkDescription.Text = dvTravel["Description"].ToString();
}
Image imgNiveau = e.Item.FindControl("imgNiveau") as Image;
if (imgNiveau == null) return;
if (imgNiveau != null)
{
imgNiveau.ImageUrl = dvTravel["Niveau"].ToString();
}
}
}
protected void grdTravel_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "RowClick" && e.Item is GridDataItem)
{
string url = string.Empty;
DataRowView oRow = (DataRowView)e.Item.DataItem;
string TravelId = oRow["TravelId"].ToString();
if (TravelType == "Default")
TravelType = PreviousTravelType;
url = UrlHelper.Instance.GetSiteUrl() + "/nl/ReisDetail/" +
TravelType + "/" + TravelId + ".aspx";
Response.Redirect(url);
}
}
private DataTable GetAllTravels()
{
return CreateDataTableFromList(GetTravel());
}
private DataTable CreateDataTableFromList(List<ARTravel> List)
{
DataTable oTable = new DataTable();
oTable.Columns.Add("Id", typeof(Int32));
oTable.Columns.Add("TravelId");
oTable.Columns.Add("Destination");
oTable.Columns.Add("Description");
oTable.Columns.Add("DepartureDate");
oTable.Columns.Add("ReturnDate");
oTable.Columns.Add("Niveau");
foreach (ARTravel oItem in List)
{
DataRow oRow = oTable.NewRow();
oRow["Id"] = oItem.Id;
oRow["TravelId"] = oItem.TravelId;
oRow["Destination"] = oItem.Destination.Name;
oRow["Description"] = oItem.Description;
oRow["DepartureDate"] = oItem.DepartureDate.ToShortDateString();
oRow["ReturnDate"] = oItem.ReturnDate.ToShortDateString();
oRow["Niveau"] = UrlHelper.Instance.GetSiteUrl() + "/img/ventjes" + oItem.Niveau.Grade + ".gif";
oTable.Rows.Add(oRow);
}
return oTable;
}
private List<ARTravel> GetTravel()
{
TravelType = Request.QueryString["ReisType"];
if (TravelType == "Default")
TravelType = PreviousTravelType;
ARTravel graph = new ARTravel(new ARNiveau(), new ARType(TravelType),new ARDestination());
List<ARTravel> reizen = TravelFacade.Instance.GetTravels(true,TravelType, graph);
return reizen;
}
}