Hi, I am using telerik radgrid in my application with below markup : When in the application i m increasing the page size from 20 to 50 or more , it thows me error. Could you pls suggest what needs to be corrected from code perspective?
<telerik:RadGrid ID="gvHazardCategories" runat="server"
AutoGenerateColumns="False"
AllowPaging="True"
PageSize="20"
AllowSorting="True"
DataSourceID="odsHazardCategories"
GridLines="None"
AllowFilteringByColumn="true"
OnInit="gvHazardCategories_Init"
OnDeleteCommand="gvHazardCategories_DeleteCommand"
OnInsertCommand="gvHazardCategories_InsertCommand"
OnUpdateCommand="gvHazardCategories_UpdateCommand"
OnItemCreated="gvHazardCategories_ItemCreated"
OnItemCommand="gvHazardCategories_ItemCommand"
OnPreRender="gv_PreRender"
>
using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Fourleaf.Websites.DEC.Web;using Fourleaf.Websites.DEC.Core;using Fourleaf.Websites.DEC.Business;using Telerik.Web.UI;using System.Collections.Specialized;using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;public partial class DataAdmin_HazardCategories : BasePage{ protected void Page_Load(object sender, EventArgs e) { SetupPage("Hazard Category Management", FourleafUser.UserLevelType.Administrator); } #region gvHazardCategories protected void gvHazardCategories_Init(object sender, EventArgs e) { try { TelerikUtil.ConfigureFilterItems(((RadGrid)sender).FilterMenu); } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, CurrentSite.Instance.Error_UI_Policy_Name); NameValueCollection errDetail = new NameValueCollection(1); errDetail.Add("UserErrorMessage", UserErrorMessage); ExceptionHandler handler = new ExceptionHandler(ex, errDetail); } } //protected void gvHazardCategories_hPageIndexChanged(object sender, GridCommandEventArgs e) //{ // try // { // gvHazardCategories.CurrentPageIndex = e.NewPageIndex; // //ShowGrid(-1); // gvHazardCategories.DataBind(); // } // catch (Exception ex) // { // bool rethrow = ExceptionPolicy.HandleException(ex, CurrentSite.Instance.Error_UI_Policy_Name); // NameValueCollection errDetail = new NameValueCollection(1); // errDetail.Add("UserErrorMessage", UserErrorMessage); // ExceptionHandler handler = new ExceptionHandler(ex, errDetail); // } //} protected void gvHazardCategories_ItemCommand(object source, GridCommandEventArgs e) { try { //Used to close any open edit forms when the insert form is displayed and vice versa RadGrid grid = (RadGrid)source; TelerikUtil.CloseOppositeForm(grid, e); if (e.Item is GridEditableItem & !e.Item.IsInEditMode) { Hazard_Category _Business = new Hazard_Category(); //Get edited item GridEditableItem editedItem = (GridEditableItem)e.Item; //Get values int HazardCategoryId = Conversion.ToInt32Default(editedItem.GetDataKeyValue("Hazard_Category_Id"), 0); if (HazardCategoryId > 0) { switch (e.CommandName.ToUpper()) { case "UP": _Business.MoveUp(HazardCategoryId); gvHazardCategories.Rebind(); break; case "DOWN": _Business.MoveDown(HazardCategoryId); gvHazardCategories.Rebind(); break; } } } } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, CurrentSite.Instance.Error_UI_Policy_Name); NameValueCollection errDetail = new NameValueCollection(1); errDetail.Add("UserErrorMessage", UserErrorMessage); ExceptionHandler handler = new ExceptionHandler(ex, errDetail); } } protected void gvHazardCategories_DeleteCommand(object source, GridCommandEventArgs e) { try { //Get edited item GridEditableItem editedItem = (GridEditableItem)e.Item; //Get values int HazardCategoryId = Conversion.ToInt32Default(editedItem.GetDataKeyValue("Hazard_Category_Id"), 0); //Check values are legit if (HazardCategoryId <= 0) { e.Canceled = true; } else { //Do the work Hazard_Category _Business = new Hazard_Category(); _Business.Delete(HazardCategoryId); } } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, CurrentSite.Instance.Error_UI_Policy_Name); NameValueCollection errDetail = new NameValueCollection(1); errDetail.Add("UserErrorMessage", UserErrorMessage); ExceptionHandler handler = new ExceptionHandler(ex, errDetail); } } protected void gvHazardCategories_InsertCommand(object source, GridCommandEventArgs e) { try { //Get edited item GridEditableItem editedItem = (GridEditableItem)e.Item; //Get error label and reset it Label lblError = (Label)Functions.FindControlRecursive(editedItem.OwnerTableView, "lblError"); lblError.Text = ""; //Get values string HazardCategoryName = Conversion.ToStringDefault(((TextBox)Functions.FindControlRecursive(editedItem.OwnerTableView, "txtEditName")).Text); int AboveOrBelow = Conversion.ToInt32Default(((RadComboBox)Functions.FindControlRecursive(editedItem.OwnerTableView, "cmbAboveBelow")).SelectedValue, 0); int ReferenceId = Conversion.ToInt32Default(((RadComboBox)Functions.FindControlRecursive(editedItem.OwnerTableView, "cmbHazardCategories")).SelectedValue, 0); //Check values are legit if (HazardCategoryName.Trim() == "") { e.Canceled = true; } else { //Do the work Hazard_Category _Business = new Hazard_Category(); int i = _Business.Insert(HazardCategoryName, AboveOrBelow, ReferenceId); if (i == -1) { lblError.Text = string.Format("The database already contains a record for '{0}'", HazardCategoryName); lblError.Visible = true; e.Canceled = true; } } //Check to see if we need to display error if (e.Canceled == true && lblError.Text == "") { lblError.Text = "Please complete all the required fields."; lblError.Visible = true; } } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, CurrentSite.Instance.Error_UI_Policy_Name); NameValueCollection errDetail = new NameValueCollection(1); errDetail.Add("UserErrorMessage", UserErrorMessage); ExceptionHandler handler = new ExceptionHandler(ex, errDetail); } } protected void gvHazardCategories_UpdateCommand(object source, GridCommandEventArgs e) { try { //Get edited item GridEditableItem editedItem = (GridEditableItem)e.Item; //Get error label and reset it Label lblError = (Label)Functions.FindControlRecursive(editedItem.OwnerTableView, "lblError"); lblError.Text = ""; //Get values int HazardCategoryId = Conversion.ToInt32Default(editedItem.GetDataKeyValue("Hazard_Category_Id"), 0); string HazardCategoryName = Conversion.ToStringDefault(((TextBox)editedItem.FindControl("txtEditName")).Text); int HazardCategorySort = Conversion.ToInt32Default(editedItem.GetDataKeyValue("Hazard_Category_Sort"), 0); //Check values are legit if (HazardCategoryId <= 0 || HazardCategoryName.Trim() == "") { e.Canceled = true; } else { //Do the work Hazard_Category _Business = new Hazard_Category(); _Business.Update(HazardCategoryId, HazardCategoryName, HazardCategorySort); } //Check to see if we need to display error if (e.Canceled == true && lblError.Text == "") { lblError.Text = "Please complete all the required fields."; lblError.Visible = true; } } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, CurrentSite.Instance.Error_UI_Policy_Name); NameValueCollection errDetail = new NameValueCollection(1); errDetail.Add("UserErrorMessage", UserErrorMessage); ExceptionHandler handler = new ExceptionHandler(ex, errDetail); } } protected void gvHazardCategories_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) { try { if (e.Item is GridHeaderItem) { } if (e.Item is GridDataItem) { GridDataItem dataItem = e.Item as GridDataItem; Button btDelete = null; int CategoryCount = Conversion.ToInt32Default(dataItem.GetDataKeyValue("Hazard_Category_Count")); btDelete = ((Button)dataItem["HC_Actions"].Controls[3]); if (CategoryCount == 0) { btDelete.Visible = true; } else { btDelete.Visible = false; } //Hide sort order buttons int IsFirst = Conversion.ToInt32Default(dataItem.GetDataKeyValue("IsFirst")); int IsLast = Conversion.ToInt32Default(dataItem.GetDataKeyValue("IsLast")); if (IsFirst == 1) { dataItem["HC_Up"].Controls[0].Visible = false; dataItem["HC_Up"].Text = " "; } if (IsLast == 1) { dataItem["HC_Down"].Controls[0].Visible = false; dataItem["HC_Down"].Text = " "; } } if (e.Item is GridEditFormItem && e.Item.IsInEditMode) { GridEditFormItem item = (GridEditFormItem)e.Item; //Loop through all items in grid adding help tooltips where necessary foreach (Control c in item.Controls[1].Controls[0].Controls) { if (c.GetType() == typeof(Label)) { Label lbl = (Label)item.FindControl(c.ID); if (lbl.CssClass == "help_label") { lbl.ToolTip = new HelpText().GetTooltip(c.ID, "Hazard Category Management"); } } } } } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, CurrentSite.Instance.Error_UI_Policy_Name); NameValueCollection errDetail = new NameValueCollection(1); errDetail.Add("UserErrorMessage", UserErrorMessage); ExceptionHandler handler = new ExceptionHandler(ex, errDetail); } } protected void gv_PreRender(object sender, System.EventArgs e) { RadGrid aGrid = (RadGrid)sender; if (aGrid.MasterTableView.IsItemInserted) { RadComboBox aCombo = (RadComboBox)Functions.FindControlRecursive(aGrid.MasterTableView, "cmbHazardCategories"); if (aCombo != null) { aCombo.Items[aCombo.Items.Count - 1].Selected = true; } } } #endregion protected void Toolbar_ButtonClick(object sender, RadToolBarEventArgs e) { try { RadToolBarButton thisButton = (RadToolBarButton)e.Item; if (thisButton.CommandName.ToUpper() == "CLEARFILTERS") { GridTableView gtv = ((GridTableView)((RadToolBar)sender).Parent.Parent.Parent.Parent.Parent); foreach (GridColumn column in gtv.Columns) { column.CurrentFilterFunction = GridKnownFunction.NoFilter; column.CurrentFilterValue = string.Empty; } gtv.FilterExpression = string.Empty; gtv.Rebind(); } } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, CurrentSite.Instance.Error_UI_Policy_Name); NameValueCollection errDetail = new NameValueCollection(1); errDetail.Add("UserErrorMessage", UserErrorMessage); ExceptionHandler handler = new ExceptionHandler(ex, errDetail); } }}
<%@ Page Title="" Language="C#" MasterPageFile="../Core/MasterPage.master" AutoEventWireup="true" CodeFile="HazardCategories.aspx.cs" Inherits="DataAdmin_HazardCategories" %>
<%@ Register TagPrefix="ucDEC" TagName="HelpPage" Src="../UserControls/HelpPage.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderMain" Runat="Server">
<span style="float: right; line-height: 20px;">
<ucDEC:HelpPage ID="ucHelp" runat="server" PageName="Hazard_Category" Title="Help - Hazard Category Management" />
</span>
<h4>Hazard Category Management</h4>
<asp:Panel ID="pnlInstructions" runat="server">
<p>
Each requirement is classified according to one of the Hazard Categories from the list shown below.
<br /><br />
This screen is used to modify the list of existing Hazard Categories or add new ones. A new Hazard Category can be inserted between existing categories if required.
</p>
</asp:Panel>
<telerik:RadGrid ID="gvHazardCategories" runat="server"
AutoGenerateColumns="False"
AllowPaging="True"
PageSize="20"
AllowSorting="True"
DataSourceID="odsHazardCategories"
GridLines="None"
AllowFilteringByColumn="true"
OnInit="gvHazardCategories_Init"
OnDeleteCommand="gvHazardCategories_DeleteCommand"
OnInsertCommand="gvHazardCategories_InsertCommand"
OnUpdateCommand="gvHazardCategories_UpdateCommand"
OnItemCreated="gvHazardCategories_ItemCreated"
OnItemCommand="gvHazardCategories_ItemCommand"
OnPreRender="gv_PreRender"
>
<MasterTableView
DataKeyNames="Hazard_Category_Id, Hazard_Category_Nm, Hazard_Category_Count, Hazard_Category_Sort, IsFirst, IsLast"
DataSourceID="odsHazardCategories"
InsertItemPageIndexAction="ShowItemOnCurrentPage"
CommandItemDisplay="Top"
TableLayout="Fixed"
>
<PagerStyle AlwaysVisible="true" />
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<CommandItemTemplate>
<telerik:RadToolBar ID="tbGroups" runat="server" OnButtonClick="Toolbar_ButtonClick">
<Items>
<telerik:RadToolBarButton Text="New"
Visible="true"
CommandName='<%# RadGrid.InitInsertCommandName %>' ImageUrl="../Core/images/new.gif">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton Text="Refresh"
Visible="true"
CommandName='<%# RadGrid.RebindGridCommandName %>' ImageUrl="../Core/images/refresh.gif">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton Text="Export to Excel"
Visible="false"
CommandName='<%# RadGrid.ExportToExcelCommandName %>' ImageUrl="../Core/images/excel.gif">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton Text="Output to PDF"
Visible="false"
CommandName='<%# RadGrid.ExportToPdfCommandName %>' ImageUrl="../Core/images/pdf.gif">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton Text="Clear Filters"
Visible="true"
CommandName='CLEARFILTERS' ImageUrl="../Core/images/clear_filters.gif">
</telerik:RadToolBarButton>
</Items>
</telerik:RadToolBar>
</CommandItemTemplate>
<Columns>
<telerik:GridBoundColumn UniqueName="HC_ID" HeaderText=""
ReadOnly="true" Visible="false"
DataField="Hazard_Category_Id">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="HC_Sort" HeaderText=""
ReadOnly="true" Visible="false"
DataField="Hazard_Category_Sort">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="HC_Name" HeaderText="Name"
AutoPostBackOnFilter="true"
CurrentFilterFunction="Contains"
ShowFilterIcon="false"
DataField="Hazard_Category_Nm">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn UniqueName="HC_Up"
HeaderStyle-Width="40px"
ButtonType="ImageButton"
CommandName="Up"
Text="Move Up"
ImageUrl="../Core/Images/move_up.gif"
ItemStyle-HorizontalAlign="Center"
ItemStyle-VerticalAlign="Middle"
>
</telerik:GridButtonColumn>
<telerik:GridButtonColumn UniqueName="HC_Down"
HeaderStyle-Width="40px"
ButtonType="ImageButton"
CommandName="Down"
ImageUrl="../Core/Images/move_down.gif"
Text="Move Down"
ItemStyle-HorizontalAlign="Center"
ItemStyle-VerticalAlign="Middle"
>
</telerik:GridButtonColumn>
<telerik:GridTemplateColumn UniqueName="HC_Actions" HeaderText="" Visible="true"
AllowFiltering="false"
HeaderStyle-Width="120px"
>
<ItemTemplate>
<asp:Button ID="bt_HC_Edit" runat="server" Text="Edit" CommandName="Edit" />
<asp:Button ID="bt_HC_Delete" runat="server" Text="Delete" CommandName="Delete" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings EditColumn-ButtonType="PushButton" EditFormType="Template">
<FormTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lblError" runat="server" Text="" Visible="false" CssClass="errormsg" />
</td>
</tr>
<tr>
<td><asp:Label ID="lblEditName" runat="server" Text="Hazard Name: " CssClass="">Hazard Name: <span class="errormsg">*</span></asp:Label></td>
<td><asp:TextBox ID="txtEditName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Hazard_Category_Nm")%>'></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="lblInsertItem" runat="server" Text="Insert Hazard "
Visible='<%# (Container is GridEditFormInsertItem) ? true : false %>' CssClass="">Insert Hazard: <span class="errormsg">*</span></asp:Label></td>
<td>
<telerik:RadComboBox ID="cmbAboveBelow" runat="server"
Visible='<%# (Container is GridEditFormInsertItem) ? true : false %>'
>
<Items>
<telerik:RadComboBoxItem Text="Below" Value="1" />
<telerik:RadComboBoxItem Text="Above" Value="-1" />
</Items>
</telerik:RadComboBox>
<asp:Literal ID="litSpacer" runat="server" text=" " Visible='<%# (Container is GridEditFormInsertItem) ? true : false %>' />
<telerik:RadComboBox ID="cmbHazardCategories" runat="server"
AppendDataBoundItems="true"
EnableItemCaching="true"
DataSourceID="odsHazardCategories"
DataTextField="Hazard_Category_Nm"
DataValueField="Hazard_Category_Id"
Width="200px"
Visible='<%# (Container is GridEditFormInsertItem) ? true : false %>'
>
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td> </td>
<td class="radGridEditLabel">
<asp:Button ID="bt_Detail_Update" runat="server"
CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' />
<asp:Button ID="bt_Detail_Cancel" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
<ValidationSettings
CommandsToValidate="PerformInsert,Update"
EnableValidation="true"
ValidationGroup="vgHazardCategory" />
<GroupingSettings
CaseSensitive="False" />
<ClientSettings>
<Selecting AllowRowSelect="false" />
</clientsettings>
</telerik:RadGrid>
<asp:ObjectDataSource ID="odsHazardCategories" runat="server"
SelectMethod="ListOrdered"
TypeName="Fourleaf.Websites.DEC.Business.Hazard_Category" >
</asp:ObjectDataSource>
</asp:Content>