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

[Solved] Ajaxify prometheus RadGrid

4 Answers 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sean Eby
Top achievements
Rank 1
Sean Eby asked on 18 Feb 2008, 05:02 PM
All,
I've been struggling with how to ajaxify the prometheus RadGrid for a few days now, and would like some pointers.  In previous versions, I'd simply have to set the .EnableAjax, and the grid would be ajaxified.  Apparently, this functionaltiy is now gone.

So, here is my setup.

MasterPage -> ContentPage -> UserControl -> RadGrid

I'd like to programatically ajaxify the Grid for Paging, Sorting and Filtering.  I have the RadAjaxManager and ScriptManager on my MasterPage.

I have tried several varieties of:

RadAjaxManager.AjaxSettings.AddAjaxSetting(myBaseDataGrid, myBaseDataGrid)

But all, with no avail.

It doesn't seem that it should be this hard.  Can someone point me in the right direction?

4 Answers, 1 is accepted

Sort by
0
Accepted
Fernandes
Top achievements
Rank 1
answered on 18 Feb 2008, 08:31 PM
Hi Sean,

According to your scenario, and since you want to add ajax programatically, this is what I suggest you to do:

1- Create a masterpage with a scriptManager and a RadAjaxManager:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!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>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
        <asp:ScriptManager ID="ScriptManager1" runat="server">  
        </asp:ScriptManager> 
        <telerik:radajaxmanager id="RadAjaxManager1" runat="server">  
        </telerik:radajaxmanager> 
          
        <div> 
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">  
            </asp:ContentPlaceHolder> 
        </div> 
    </form> 
</body> 
</html> 

2- Create a page based onthat masterpage:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %> 
 
<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">  
    <uc1:WebUserControl ID="WebUserControl1" runat="server" /> 
</asp:Content> 


3- This is a sample usercontrol with a grid (based on NorthWind database):
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<telerik:radgrid id="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None" AllowPaging="true" PageSize="3">  
    <ExportSettings> 
        <Pdf FontType="Subset" PaperSize="Letter" /> 
        <Excel Format="Html" /> 
    </ExportSettings> 
    <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" 
        DataKeyNames="ProductID" DataSourceID="SqlDataSource1" Dir="LTR" Frame="Border" 
        TableLayout="Auto">  
        <EditFormSettings> 
            <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">  
            </EditColumn> 
        </EditFormSettings> 
        <Columns> 
            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ProductID" DataType="System.Int32" 
                FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="ProductID" 
                ReadOnly="True" SortExpression="ProductID" UniqueName="ProductID">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ProductName" 
                FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="ProductName" 
                SortExpression="ProductName" UniqueName="ProductName">  
            </telerik:GridBoundColumn> 
            <telerik:GridCheckBoxColumn CurrentFilterFunction="NoFilter" DataField="Discontinued" 
                DataType="System.Boolean" FilterListOptions="VaryByDataType" ForceExtractValue="None" 
                HeaderText="Discontinued" SortExpression="Discontinued" UniqueName="Discontinued">  
            </telerik:GridCheckBoxColumn> 
        </Columns> 
        <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
            Resizable="False" Visible="False">  
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
        <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
            Visible="False">  
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
    </MasterTableView> 
</telerik:radgrid> 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=PORTOSANTO;Initial Catalog=Northwind;Integrated Security=True" 
    ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP (10) ProductID, ProductName, Discontinued FROM Products">  
</asp:SqlDataSource> 
 

4- And finally (and the most important), the userControl codebehind:
using System;  
using System.Data;  
using System.Configuration;  
using System.Collections;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
using Telerik.Web.UI;  
 
public partial class WebUserControl : System.Web.UI.UserControl  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        //Ajaxify the Grid  
 
        // First: Get the Ajax Manager on the MasterPage.  
        RadAjaxManager ajaxManager = (RadAjaxManager)this.Page.Master.FindControl("RadAjaxManager1");  
 
        // Second: Add the Ajax settings.  
        AjaxSetting setting = new AjaxSetting("stg_" + RadGrid1.ID);  
        setting.AjaxControlID = RadGrid1.ID;  
 
        AjaxUpdatedControl updControl = new AjaxUpdatedControl();  
        updControl.ControlID = RadGrid1.ID;  
 
        setting.UpdatedControls.Add(updControl);  
        ajaxManager.AjaxSettings.Add(setting);  
 
    }  
}  
 

This is my suggestion!

Give it a try

Fernandes
0
Sean Eby
Top achievements
Rank 1
answered on 18 Feb 2008, 09:35 PM
Wow, that worked great.

Any idea why we can't just use the AjaxSettings.AddAjaxSetting() functionality?
0
Leon
Top achievements
Rank 1
answered on 19 Feb 2008, 06:23 AM
Sean,

The AddAjaxSetting method should do it as well but I'd like to suggest another option - do that entirely declaratively. Put Manager Proxy in your user control and configure it through the property builder to ajaxify and update the Grid. This is all you need.

http://www.telerik.com/demos/aspnet/prometheus/Ajax/Examples/Manager/MasterPage/DefaultCS.aspx

- Leon

0
Sean Eby
Top achievements
Rank 1
answered on 19 Feb 2008, 03:04 PM
Unfortunately, I cannot use the Declaritive approach, as all my Usercontrols are dynamic.

Also, I can get Fernandes's approach to work, but I cannot get the AddAjaxSetting() to work at all.
Tags
Grid
Asked by
Sean Eby
Top achievements
Rank 1
Answers by
Fernandes
Top achievements
Rank 1
Sean Eby
Top achievements
Rank 1
Leon
Top achievements
Rank 1
Share this question
or