Grid Not Updating Using ajaxRequest

3 posts, 1 answers
  1. Jimmy Hill
    Jimmy Hill avatar
    9 posts
    Member since:
    Nov 2007

    Posted 03 Dec 2009 Link to this post

    I am attempting to update a grid's datasource with a JavaScript initiated AJAX request. The code "appears" to work - no errors and the RadAjaxLoadingPanel becomes visible but the grid does not update. Any ideas?

    JavaScript:
    function test(itemID, qty, dueDate)  
                {  
                    var aryData = new Array();  
                    aryData[0] = itemID;  
                    aryData[1] = qty;  
                    aryData[2] = dueDate;  
                      
                    var ajaxManager = $find("<%= RadAjaxManagerNewWorkOrder.ClientID %>");  
                    ajaxManager.ajaxRequest(aryData.join("|"));  
                      
                    return false;  
                } 
    Asp.Net
    <telerik:RadAjaxManager ID="RadAjaxManagerNewWorkOrder" runat="server" OnAjaxRequest="RadAjaxManagerNewWorkOrder_AjaxRequest">  
     
    <AjaxSettings> 
     
    <telerik:AjaxSetting AjaxControlID="RadAjaxManagerNewWorkOrder">  
     
    <UpdatedControls> 
     
    <telerik:AjaxUpdatedControl ControlID="rgSelectedKits" LoadingPanelID="RadAjaxLoadingPanel1" /> 
     
    </UpdatedControls> 
     
    </telerik:AjaxSetting> 
     
    </AjaxSettings> 
     
    </telerik:RadAjaxManager> 
     
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">  
     
    </telerik:RadAjaxLoadingPanel> 
     
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnableTheming="True">  
     
    </telerik:RadScriptManager> 
     
     
    <telerik:RadGrid ID="rgSelectedKits" runat="server" Skin="Web20" EnableLinqExpressions="true" AllowAutomaticUpdates="true"      
                    AutoGenerateColumns="False" GridLines="None" AllowSorting="True" >    
                    <MasterTableView>    
                    <RowIndicatorColumn>    
                        <HeaderStyle Width="20px"></HeaderStyle>    
                    </RowIndicatorColumn>    
        
                    <ExpandCollapseColumn>    
                        <HeaderStyle Width="20px"></HeaderStyle>    
                    </ExpandCollapseColumn>    
                        <Columns>    
                            <telerik:GridBoundColumn DataField="ItemID" Display="False"      
                                HeaderText="Item ID" UniqueName="ItemID">     
                            </telerik:GridBoundColumn>    
                            <telerik:GridBoundColumn DataField="ItemNumber" HeaderText="Item Number"      
                                UniqueName="ItemNumber">     
                            </telerik:GridBoundColumn>    
                            <telerik:GridBoundColumn DataField="ItemName" HeaderText="Item Name"      
                                UniqueName="ItemName">     
                            </telerik:GridBoundColumn>    
                            <telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity"      
                                UniqueName="Quantity">     
                            </telerik:GridBoundColumn>    
                            <telerik:GridBoundColumn DataField="DueDate" HeaderText="Due Date"      
                                UniqueName="DueDate">     
                            </telerik:GridBoundColumn>    
                        </Columns>    
                    </MasterTableView>    
                </telerik:RadGrid>    
     
    C#:
    using System;  
    using System.Collections;  
    using System.Configuration;  
    using System.Data;  
    using System.Linq;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.HtmlControls;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Xml.Linq;  
    using Telerik.Web.UI;  
    using System.Collections.Generic;  
     
    public partial class NewWorkOrder : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!IsPostBack)  
            {  
                rgSelectedKits.DataSource = new List<WorkOrderKit>();  
            }  
     
            rComboKits.LoadingMessage = "Locating Kit...";  
        }  
        protected void rComboKits_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)  
        {  
            if (!string.IsNullOrEmpty(e.Text))  
            {  
                SFAF_PODDataContext db = new SFAF_PODDataContext();  
                rComboKits.DataTextField = "itemnumber";  
                rComboKits.DataValueField = "itemid";  
     
                List<InvItem> results = (from items in db.InvItems  
                                         join kitIndicator in db.InvItemKitIndicators on items.itemid equals kitIndicator.itemid  
                                         where items.itemnumber.ToUpper().StartsWith(e.Text.ToUpper()) ||  
                                         items.itemtext.ToUpper().Contains(e.Text.ToUpper())  
                                         && items.custid == 1431  
                                         && kitIndicator.IsKit == true 
                                         select items).ToList();  
     
                rComboKits.DataSource = results;  
                rComboKits.DataBind();  
            }  
        }  
          
        public void RadAjaxManagerNewWorkOrder_AjaxRequest(object sender, AjaxRequestEventArgs e)  
        {  
            SFAF_PODDataContext db = new SFAF_PODDataContext();  
            List<String> lstData = e.Argument.Split('|').ToList();  
     
            int itemID = Convert.ToInt32(lstData[0]);  
            int qty = Convert.ToInt32(lstData[1]);  
     
            List<String> dates = lstData[2].Split('/').ToList();  
            int month = Convert.ToInt32(dates[0]);  
            int day = Convert.ToInt32(dates[1]);  
            int year = Convert.ToInt32(dates[2]);  
     
            InvItem item = db.InvItems.SingleOrDefault(items => items.itemid == itemID);  
     
            DateTime dueDate = new DateTime(year, month, day);  
            WorkOrderKit woKit = new WorkOrderKit(itemID, qty, item.itemnumber, item.itemtext, dueDate);  
     
            UpdateWoKitGrid(woKit);  
        }  
        private void UpdateWoKitGrid(WorkOrderKit woKit)  
        {  
            List<WorkOrderKit> currentGridKits = new List<WorkOrderKit>();  
     
            foreach (GridItem item in rgSelectedKits.Items)  
            {  
                currentGridKits.Add((WorkOrderKit)item.DataItem);  
            }  
     
            currentGridKits.Add(woKit);  
     
            rgSelectedKits.DataSource = currentGridKits;  
            rgSelectedKits.DataBind();  
        }  
    }  
     
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Dec 2009 Link to this post

    Hello Jimmy Hill,

    Can you try placing the RadScriptManager declaration on the top of page (before RadAjaxManager declaration) and check whether it is working fine?

    -Shinu.
  3. Jimmy Hill
    Jimmy Hill avatar
    9 posts
    Member since:
    Nov 2007

    Posted 04 Dec 2009 Link to this post

    Shinu,

    That did it. Thank you very much! It's amazing that such a simple fix could cause so many hours of frustration.
Back to Top