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

[Solved] AJAX Radgrid in a webpart

6 Answers 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Willen
Top achievements
Rank 1
Paul Willen asked on 23 Nov 2009, 01:50 PM
Hello,

I hope someone can help me with my issues I've got.
First of all I'll try to explain what I've got.

I've got a Telerik RadGrid built into a WebPart. This radgrid has a SharePoint list as a datasource. At the moment there is no need to edit or delete any items from the sharepoint list via the RadGrid. I was able to set paging on and some filter methods.

Now my goal is to have the same RadGrid in the SharePoint WebPart, but now AJAX-enabled.
Especially the paging should be handled with AJAX. I think I've read about every article on this website and just can't seem to find any good documentation how to ajax-enable a telerik radgrid.

I've read this article
http://www.telerik.com/help/aspnet-ajax/create-ajax-enabled-sharepoint-webpart-radcontrols.html
and was able to get this timer update to work.  I just can't seem to find a way how to enable my RadGrid for AJAX.

It seems that all the information out there is based on web applications with a designer mode.

I've also tried the Telerik SharePoint demo (http://sharepoint.telerik.com/Pages/default.aspx) and analyzed the code, but it seems that this too is not built into a webpart.

I hope you can help me with this issue. And I gave enough information about my problem.
Thanks in advance for helping me

Paul



6 Answers, 1 is accepted

Sort by
0
Jerry Chen
Top achievements
Rank 1
answered on 26 Nov 2009, 08:05 AM
Hi Paul ,

    I have the same issue with you. I want to custom a webpart to bind a view of a SharePoint list. Uses can add/modify/delete/query from the webpart to improve the list view. However, I 've no idea how to figure it out.
    Is there anyone can help us with the issue?

thanks in advance
Jerry
0
Yavor
Telerik team
answered on 26 Nov 2009, 08:59 AM
Hello,

Basically, in order to handle the required functionality, you need to created and setup the ajax settings for the manager dynamically. Additional information on this is availble in the following article:

http://www.telerik.com/help/aspnet-ajax/ajxaddajaxsettingsprogrammatically.html

Additionally, the code below demonstrates a similar task:

.cs
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
  
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
  
using Telerik.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
  
namespace RadGridAutoRefreshWebPart
{
    [Guid("b7297f44-2c42-426f-9f7a-fbfbc95f713e")]
    public class RadGridAutoRefreshWebPart : Microsoft.SharePoint.WebPartPages.WebPart
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
  
            ((RadAjaxManager)FindControl("RadAjaxManager1")).AjaxSettings.AddAjaxSetting(FindControl("radCombo"), FindControl("RadGrid1"));
  
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
  
            Page.ClientScript.RegisterStartupScript(typeof(RadGridAutoRefreshWebPart), this.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);
            if (this.Page.Form != null)
            {
                string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
                if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
                {
                    this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
                }
            }
  
            ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
            if (scriptManager == null)
            {
                scriptManager = new RadScriptManager();
                Page.Form.Controls.Add(scriptManager);
            }
            EnsureChildControls();
        }
  
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
  
            RadComboBox combo = new RadComboBox();
            combo.ID = "radCombo";
            combo.AutoPostBack = true;
            combo.Items.Add(new RadComboBoxItem("05","05"));
            combo.Items.Add(new RadComboBoxItem("15", "15"));
            combo.Items.Add(new RadComboBoxItem("25", "25"));
            combo.SelectedIndexChanged+=new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
  
            RadAjaxManager ajaxManager = new RadAjaxManager();
            ajaxManager.ID = "RadAjaxManager1";
            Controls.Add(ajaxManager);
            this.Page.Items.Add(typeof(RadAjaxManager), ajaxManager);
              
  
            RadGrid grid = CreateRadGrid();
  
            TextField field = new TextField();
            field.ID = "fieldControl";
            field.FieldName = "fieldControl";
            field.Value = "A text field control";
            field.Text = "A text field control";
  
  
            Button submit = new Button();
            submit.Text = "Submit selection";
            submit.Click += new EventHandler(submit_Click);
  
  
            Label lable = new Label();
            lable.ID = "selectionLable";
              
  
            this.Controls.Add(grid);
            this.Controls.Add(combo);
            this.Controls.Add(field);
            this.Controls.Add(submit);
            this.Controls.Add(lable);
  
        }
  
        protected void submit_Click(object sender, EventArgs e)
        {
            ((Label)this.FindControl("selectionLable")).Text = "Selected items: " + ((RadGrid)FindControl("RadGrid1")).SelectedIndexes.Count.ToString();
        }
  
        protected void combo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            ((RadGrid)FindControl("RadGrid1")).MasterTableView.SortExpressions.Clear();
            ((RadGrid)FindControl("RadGrid1")).Rebind();
        }
  
  
        protected virtual RadGrid CreateRadGrid()
        {
            RadGrid oGrid = new RadGrid();
            oGrid.ID = "RadGrid1";
            oGrid.Skin = "Vista";
            oGrid.AutoGenerateColumns = false;
            oGrid.AllowPaging = true;
            oGrid.AllowSorting = true;
            oGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
            oGrid.ClientSettings.Selecting.AllowRowSelect = true;
            oGrid.AllowMultiRowSelection = true;
            //oGrid.MasterTableView.AllowAutomaticInserts = false;
  
            oGrid.NeedDataSource += new GridNeedDataSourceEventHandler(oGrid_NeedDataSource);
            oGrid.InsertCommand += new GridCommandEventHandler(oGrid_InsertCommand);
                  
            GridBoundColumn StockTicker = new GridBoundColumn();
            oGrid.MasterTableView.Columns.Add(StockTicker);
            StockTicker.DataField = "StockTicker";
            StockTicker.HeaderText = "StockTicker";
              
  
            GridBoundColumn LastTrade = new GridBoundColumn();
            oGrid.MasterTableView.Columns.Add(LastTrade);
            LastTrade.DataField = "LastTrade";
            LastTrade.HeaderText = "LastTrade";
              
  
            GridBoundColumn Change = new GridBoundColumn();
            oGrid.MasterTableView.Columns.Add(Change);
            Change.HeaderText = "Change";
            Change.DataField = "Change";
            Change.ItemStyle.Font.Bold = true;
              
  
            GridBoundColumn LastUpdated = new GridBoundColumn();
            oGrid.MasterTableView.Columns.Add(LastUpdated);
            LastUpdated.DataField = "LastUpdated";
            LastUpdated.HeaderText = "LastUpdated";
              
  
  
            GridClientSelectColumn selectColumn = new GridClientSelectColumn();
            oGrid.MasterTableView.Columns.Add(selectColumn);
            selectColumn.UniqueName = "ClientSelect";
  
  
            return oGrid;
        }
  
        protected void oGrid_InsertCommand(object source, GridCommandEventArgs e)
        {
              
        }
  
        protected void oGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("StockTicker");
            dt.Columns.Add("LastTrade");
            dt.Columns.Add("Change");
            dt.Columns.Add("LastUpdated");
  
            Random random = new Random(DateTime.Now.Millisecond);
            for (int i = 0; i < 5; i++)
            {
                dt.Rows.Add("StockTicker " + random.NextDouble(), "LastTrade " + random.NextDouble(), "Change " + random.NextDouble(), "LastUpdated " + random.NextDouble());
            }
              
            ((RadGrid)source).DataSource = dt;
        }
    }
}

I hope this information helps.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jerry Chen
Top achievements
Rank 1
answered on 30 Nov 2009, 07:46 AM
Thanks, buddy.

    What I need is to binding list items with RadGrid control. There is a showcase in your site as below:
    RadGrid for MOSS

    Is there any wsp solution file like RadEditorMOSS.wsp for us to deploy? If not, how to implement the functionality like the demo.


KR
Jerry
0
Yavor
Telerik team
answered on 02 Dec 2009, 07:57 AM
Hi Jerry,

Presently, there is no such identical wsp solution for the grid. You can download the source code from the showcase which you mentioned, where the controls are statically declared in the user controls.
Alternatively, you can declare the control(s) dynamically, as shown in the code supplied earlier in the thread. I hope one of these approaches is suitable for you.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jerry Chen
Top achievements
Rank 1
answered on 07 Dec 2009, 06:10 AM
Hi Yavor,

    Thanks for your tips on how to use RadGrid in SharePoint.

KR
Jerry
   
 
0
Yavor
Telerik team
answered on 07 Dec 2009, 09:55 AM
Hello Jerry,

You can open a formal support ticket, and send a small working project, demonstrating the issue, for additional review and testing.

Sincerely yours,
Yavor
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Paul Willen
Top achievements
Rank 1
Answers by
Jerry Chen
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or