Load on Demand RadPageView

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    184 posts
    Member since:
    Feb 2009

    Posted 19 May 2009 Link to this post

    Hi. I've followed the 'Load on Demand RadPageView' demo almost to the letter except with the datasource in the web user controls which hold the RadGrid's. I have them set so that the SelectCommand is set at runtime in the code behind, because it retrieves the windows userid. The grids seem to disappear when I click on a tab. I've tried setting the OnNeedDataSource but that doesn't even seem to get fired. This doesn't happen if I have the SelectCommand in the ASCX page.

    Here is my ASCX page:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PurchaseOrders.ascx.cs" 
        Inherits="workbench_PurchaseOrders" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <telerik:RadGrid ID="rgPurchaseOrders" runat="server" AllowPaging="True" AllowSorting="True" 
        DataSourceID="sdsPurchaseOrders" GridLines="None" Skin="Vista" OnNeedDataSource="rgPurchaseOrders_OnNeedDataSource">  
        <MasterTableView AutoGenerateColumns="False" DataSourceID="sdsPurchaseOrders" NoMasterRecordsText="You have no purchase orders.">  
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px" /> 
            </ExpandCollapseColumn> 
            <AlternatingItemStyle BackColor="#F0F0F0" /> 
            <Columns> 
                <telerik:GridBoundColumn DataField="po_number" HeaderText="Order Number" SortExpression="po_number" 
                    UniqueName="po_number">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="supplier_name" HeaderText="Supplier Name" SortExpression="supplier_name" 
                    UniqueName="supplier_name">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="amount" DataType="System.Decimal" HeaderText="Amount" 
                    SortExpression="amount" UniqueName="amount">  
                </telerik:GridBoundColumn> 
            </Columns> 
        </MasterTableView> 
    </telerik:RadGrid> 
    <asp:SqlDataSource ID="sdsPurchaseOrders" runat="server" ConnectionString="<%$ ConnectionStrings:FinprodConnectionString %>" /> 

    And the code behind:

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using Telerik.Web.UI;  
    using System.Data.SqlClient;  
    using System.Data;  
    using System.Configuration;  
    using Common;  
     
    public partial class workbench_PurchaseOrders : System.Web.UI.UserControl  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!Page.IsPostBack)  
            {  
                GetDataSource();  
            }  
        }  
     
        public DataTable GetDataTable(string query)  
        {  
            DataTable myDataTable = new DataTable();  
            SqlConnection myConnection = new SqlConnection(Intranet.ConString("/Default Web Site""FinprodConnectionString"));  
            try 
            {  
                  
                myConnection.Open();  
                SqlDataAdapter adapter = new SqlDataAdapter();  
                adapter.SelectCommand = new SqlCommand(query, myConnection);  
     
                  
     
                adapter.Fill(myDataTable);  
            }  
            finally 
            {  
                myConnection.Close();  
            }  
     
            return myDataTable;  
        }  
     
        protected void rgPurchaseOrders_OnNeedDataSource(object source, GridNeedDataSourceEventArgs e)  
        {  
            GetDataSource();  
        }  
     
        void GetDataSource()  
        {  
            string userID = HttpContext.Current.User.Identity.Name.ToString().Replace("COUNCIL\\""");  
            string sqlStr = "SELECT PORDNBR AS po_number, SUPP_NAME AS supplier_name, PORD_TOT_INC_AMT2 AS amount FROM PUF_ORD_CTL WHERE (ORIG_AUTH_CODE = '" + userID + "') AND (PORD_STATUS = 'A' OR PORD_STATUS = 'D') ORDER BY PORDNBR";  
            rgPurchaseOrders.DataSource = GetDataTable(sqlStr);  
        }  
  2. Daniel
    Daniel avatar
    184 posts
    Member since:
    Feb 2009

    Posted 19 May 2009 Link to this post

    My bad. Needed to remove the DataSourceID from the grid and mastertableview. Works like a charm now.
Back to Top