This is a migrated thread and some comments may be shown as answers.

Grid Paging Not Working

4 Answers 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 14 Nov 2014, 06:41 PM
I have a number of nearly identical grids (different in the database tables only) that are all working exactly correct.  However, I have one grid that simply refuses to go past page 1.  The display file contents and the code behind contents are both attached below.  There is also a screen capture of page 1 and then subsequent pages (doesn't matter which one I include, they all look the same).

If anyone has any ideas why this page will not page forward but all of the others that essentially identical do would be most appreciated!

Thanks!

<%@ Page Title="" Language="C#" MasterPageFile="~/masters/BrokerPlusMstr.Master" AutoEventWireup="true" CodeBehind="OfcSourceList.aspx.cs" Inherits="BrokerPlusOffice.OfcSourceList" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
 
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h3>
        Sources
    </h3>
    <p>
        The Sources codes are used to describe how real estate business leads were directed to your company.
    </p>
<div class="container">
    <div class="row10">
        <div class="one column" >
              
        </div>
        <div class="fourteen columns" >
            <telerik:RadGrid ID="RadGrid1" runat="server" ></telerik:RadGrid>
        </div>
        <div class="one column" >
              
        </div>
    </div>
</div>
<br />
<div class="container">
    <div class="row10">
        <div class="sixteen columns" style="text-align: center;" >
            <telerik:RadButton ID="CreateNew" runat="server" Text="Create New" CausesValidation="False" ToolTip="Displays a form for adding a new Source to the database." UseSubmitBehavior="True" OnClick="CreateNew_Click" />
            <telerik:RadButton ID="CloseMe" runat="server" Text="Close Window" CausesValidation="False" ToolTip= "Closes this window." UseSubmitBehavior="False" OnClientClicked="closemenow" />
        </div>
    </div>
</div>
<div class="container">
    <div class="row10">
        <div class="sixteen columns" style="text-align: center;">
            <asp:Label ID="PageErrors" runat="server" Font-Bold="True" ForeColor="#C00000" Width="95%"></asp:Label>
        </div>
    </div>
</div></asp:Content>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Common;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Web.Security;
using System.Configuration;
using System.Collections;
using Telerik.Web.UI;
using ApplDB = PublixDBCS10;
using BrokerPlusDBCS10;
 
namespace BrokerPlusOffice
{
    public partial class OfcSourceList : Common.THDiBasePage
    {
        protected void Page_Init(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
 
                //  Get the users form security rules and set the buttons accordingly
                string sUserFormRules = Convert.ToString(Session["UserBrokerPlusFormsRules"]);
                string sRule = sUserFormRules.Substring(40, 1);
 
                switch (sRule)
                {
                    case "0":
                        //  the user is not authorized for this page, so send them to the error page
                        Response.Redirect("~/UserNotAuthorized.aspx");
                        break;
                    case "1":
                        //  The user is only authorized for read-only activities, so set the buttons accordingly
                        this.CreateNew.Enabled = false;
                        break;
                    case "2":
                        //  The user is authorized to update data, so leave the buttons as is
                        break;
                }
 
                GridHyperLinkColumn hypercolumn = null;
                GridBoundColumn boundcolumn = null;
 
                RadGrid1.ID = "RadGrid1";
                RadGrid1.EnableViewState = false;
                RadGrid1.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
                RadGrid1.Width = Unit.Percentage(100);
                RadGrid1.PageSize = 15;
                RadGrid1.AllowPaging = true;
                RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
                RadGrid1.AutoGenerateColumns = false;
                RadGrid1.AllowFilteringByColumn = true;
                RadGrid1.ExportSettings.ExportOnlyData = true;
                RadGrid1.ExportSettings.IgnorePaging = true;
                RadGrid1.ExportSettings.HideStructureColumns = true;
                RadGrid1.ExportSettings.OpenInNewWindow = true;
                RadGrid1.MasterTableView.CommandItemSettings.ShowExportToCsvButton = false;
                RadGrid1.MasterTableView.CommandItemSettings.ShowExportToExcelButton = false;
                RadGrid1.MasterTableView.CommandItemSettings.ShowExportToPdfButton = false;
                RadGrid1.MasterTableView.CommandItemSettings.ShowExportToWordButton = false;
                RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
                RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
                RadGrid1.MasterTableView.Width = Unit.Percentage(100);
 
                RadGrid1.MasterTableView.DataKeyNames = new string[] { "Source" };
 
                hypercolumn = new GridHyperLinkColumn();
                hypercolumn.HeaderText = "Edit";
                hypercolumn.UniqueName = "Source";
                hypercolumn.Text = "<img border=\"0\" alt=\"View\" src=\"../Icons/pencil_16.png\" />";
                hypercolumn.DataNavigateUrlFields = new string[] { "Source" };
                hypercolumn.DataNavigateUrlFormatString = "OfcSourceEdit.aspx?M=Y&K=" + "{" + "0" + "}";
                RadGrid1.MasterTableView.Columns.Add(hypercolumn);
 
                hypercolumn = null;
 
                boundcolumn = new GridBoundColumn();
                boundcolumn.UniqueName = "SourceText";
                boundcolumn.DataField = "SourceText";
                boundcolumn.HeaderText = "Source";
                boundcolumn.Visible = true;
                RadGrid1.MasterTableView.Columns.Add(boundcolumn);
 
                boundcolumn = null;
 
                RadGrid1.AllowPaging = Convert.ToBoolean(Session["ShowListsWithPaging"]);
 
            }
        }
 
        public DataTable GetDataTable()
        {
            String ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["BrokerPlus"].ConnectionString;
            DataTable dt = new DataTable();
            using (SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["BrokerPlus"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("Sources_GetAllBySource_Account", sqlcon))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@Source_Account", Convert.ToInt32(Session["UserAccount"])));
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(dt);
                        return dt;
                    }
                }
            }
        }
 
        private void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            (source as RadGrid).DataSource = GetDataTable();
        }
 
        protected void CreateNew_Click(object sender, EventArgs e)
        {
            Response.Redirect("OfcSourceEdit.aspx?M=N&K=");
        }
    }
}

4 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 19 Nov 2014, 09:27 AM
Hi Lynn,

Keep in mind that when you create RadGrid programmatic on Page_Init event handler you should not perform IsPostBack check. Please remove the check and let me know about the result. Additionally you can check out the following help article for more details.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lynn
Top achievements
Rank 2
answered on 19 Nov 2014, 07:40 PM
I commented out the postback check and the behavior is still exactly the same.  The screen captures I uploaded previously are still applicable.

I have read the other help text but have failed to find anything I should try.

Any other ideas?

Lynn
0
Kostadin
Telerik team
answered on 24 Nov 2014, 11:46 AM
Hello Lynn,

Keep in mind that when you are creating RadGrid on Page_Init event handler you have to create it entirely in code behind. For this purpose you need to remove RadGrid declaration from the mark up and create the grind as demonstrated below.
protected void Page_Init(object sender, System.EventArgs e)
{
    RadGrid grid = new RadGrid();
    ..............
}

Otherwise if you need to keep the declarative RadGrid in the mark-up you need to create it on Page_Load as demonstrated in the previously provided help article.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lynn
Top achievements
Rank 2
answered on 24 Nov 2014, 04:13 PM
The original reply solved my issue.  Thanks!
Tags
Grid
Asked by
Lynn
Top achievements
Rank 2
Answers by
Kostadin
Telerik team
Lynn
Top achievements
Rank 2
Share this question
or