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

Grid client refresh/rebind???

10 Answers 515 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Fetherolf
Top achievements
Rank 1
John Fetherolf asked on 15 Feb 2008, 02:08 PM
I have a grid that when you click an item it brings up a popup window that allows the user to edit the data for the item in the grid.  I have a callback function on the base page that I want to refresh the grid when the user hits the "save" button on the popup.  I have tried just about everything I can think of to get the grid to refresh.  How can I force the grid to update/rebind from the JavaScript callback? 

For some back ground I did do an AjaxManager.AjaxRequest();  I am getting to the NeedDataSource event on the server, but the grid is not refreshing when the AjaxRequest is finished.  How do you get this to work with Prometheus RadGrid?

Thanks,
Kevin

Code behind:
        #region Event: RadAjaxMgr_AjaxRequest  
        /// <summary>  
        /// Ajax manager request event delegate handler.  
        /// </summary>  
        /// <param name="sender">Event sender.</param>  
        /// <param name="e">Event arguments.</param>   
        private void RadAjaxMgr_AjaxRequest(object sender, AjaxRequestEventArgs e) {  
            if (e.Arguement == "RefreshGrid")  
               gridItems.Rebind();                  //  Gets here no problem  
        }
        #endregion  
 

JavaScript:
var winMgrName = "ctl00_ContentPlaceHolder1_RadWindowManager1";  
var gridUniqueID = "ctl00$ContentPlaceHolder1$gridItems";  
var gridClientID = "ctl00_ContentPlaceHolder1_gridItems";  
var ajaxManagerClientID = "ctl00_RadAjaxManager1";  
var winEditOrder = "winEditDepartment";  
 
//  Popup department editor page/window.  
function EditDepartment(deptID) {  
    OpenRadWindow(winMgrName, "EditDepartment.aspx?i=" + deptID, winEditOrder);  
}  
 
//  Callback handler from the window's OK button handler.  
function DepartmentChangeCallback() {  
    var ajaxMgr = $find(ajaxManagerClientID);  
    var gridItems = $find(gridClientID);  
      
    ajaxMgr.AjaxRequest("RefreshGrid");  
}  
 

10 Answers, 1 is accepted

Sort by
0
Accepted
Sebastian
Telerik team
answered on 18 Feb 2008, 04:06 PM
Hello Kevin,

Have you set the RadAjaxManager as initiator of the ajax request and the grid instance as updated control through the ajax manager settings? This should ensure that the grid content will be refreshed when you invoke the ajaxRequest(eventArgs) method and call Rebind() from the AjaxRequest handler.

Furthermore, verify that the underlying record in the source is updated with the new entries to see the updated content in the grid table.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
John Fetherolf
Top achievements
Rank 1
answered on 18 Feb 2008, 07:14 PM
Thanks for the help on this Steven.  I had tried what you suggested and it hadn't worked.

One detail I didn't include in the original message was that I am using master pages.  Your response did prompt me to try something that did work however.  Originally I had a RadAjaxManager (ID="RadAjaxManager1") on the master page and a RadAjaxManagerProxy (ID="RadAjaxManager1") on the content page so my initial attempt with this in the content page:

            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="gridItems" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
 

... was apparently getting confused.  However, when I changed the ID on the manager page to "RadAjaxManagerMaster" and changed the content page to look like this:

            <telerik:AjaxSetting AjaxControlID="RadAjaxManagerMaster">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="gridItems" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
 

... everything works like a champ.

Thanks for the help again,
Kevin
0
rcbarth
Top achievements
Rank 1
answered on 05 Mar 2008, 09:50 PM
Why isn't there just a simple .rebind() client method on the grid that takes care of all this stuff for us?
0
Yavor
Telerik team
answered on 06 Mar 2008, 06:58 AM
Hello Robert,

Indeed, we will consider adding this option for one of the upcoming versions of the control. For the time being, I hope the proposed workaround is suitable for you.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
HHH
Top achievements
Rank 1
answered on 05 May 2008, 03:24 PM
Hi, Did you find solution for this.

i have same problem

in ajaxrequest i m trying to bind radgrid and its not getting refreshed
and with out ajax it works fine

thanks
0
Prangadj
Top achievements
Rank 1
answered on 05 May 2008, 03:31 PM
I do not see any problem here - if you make ajax request with ajax manager and call the Rebind() method of the grid it should rebind the data in it. Debug your code to see whether every part of your code is executed, this can help you find the cause for the problem.

Prangadj
0
HHH
Top achievements
Rank 1
answered on 05 May 2008, 04:16 PM
Thanks Prangadj for the  repsond.

Ajax_request is getting call but its not refreshing the grid..
I have also done  radgrid.rebind() but it didnt work out..

telerik

:RadAjaxManager ID="RadAjaxManager1" runat="server" >

<AjaxSettings>

<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">

<UpdatedControls>

<telerik:AjaxUpdatedControl ControlID="Rad_Grid" />

</UpdatedControls>

</telerik:AjaxSetting>

</AjaxSettings>

</

telerik:RadAjaxManager>

.CS file

Public Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest

Rad_Grid.DataSource =

DirectCast(Session("temp"), DataTable)

Rad_Grid.Rebind()

End Sub




any help with this..thanks
0
HHH
Top achievements
Rank 1
answered on 05 May 2008, 09:11 PM
Hi I found the solution..

My Script Tag was on Head Tag and i put in Body and it works
i dont know y ..

0
altaf
Top achievements
Rank 1
answered on 16 Sep 2008, 10:06 AM
i am using the 2008.2.723.20 version.$0$0$0$0i am also facing the same problem.$0$0$0$0$0$0$0$0i have an image in the grid.$0$0grid is rebinding and needdatasource event is also working fine.$0$0$0$0$0but image in the grid is not changing but when i refresh the whole page then$0$0image is display.$0$0$0$0$0can any body help me urgently.$0$0
0
David Simmonds
Top achievements
Rank 1
answered on 26 May 2010, 12:41 AM
I am having a similar problem. I have a column in the grid that is a GridTemplateColumn. In it is an ImageButton. When the grid binds, I handle the ItemDataBound event. I get the ImageButton from the grid row using Item.FindControl. If the value of one of the columns is 0 I set the ImageUrl and ToolTipto indicate an Add functionality, otherwise I set the ImageUrl and ToolTip to indicate a Delete functionality. I also set the ImageButton Attributes["onclick"] to a specific javascript method; one for add, one for delete. Each javascript method does some work and then calls the ajaxRequest method of the AjaxManager; each with a different argument. This all works perfectly when the grid first initializes. If I click the ImageButton everything works including the call to AjaxRequest. In the handler I do a database add or delete and then call Rebind for the grid. ItemDataBound event is called but the grid ImageButton does not change the image. I have included the code below. If someone can tell me how to cause the ImageButton to visually change the image I would appreciate it.

<%@ Page Title="" Language="C#" MasterPageFile="~/NestedMasterPage2.master" AutoEventWireup="true" CodeBehind="ContractorsList.aspx.cs" Inherits="CharityCheck.Admin.ContractorsList" %> 
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %> 
<%@ Register tagprefix="igtxt" namespace="Infragistics.WebUI.WebDataInput" Assembly="Infragistics35.WebUI.WebDataInput.v10.1, Version=10.1.20101.2039, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
 
<%@ Register tagprefix="igtbl" namespace="Infragistics.WebUI.UltraWebGrid" Assembly="Infragistics35.WebUI.UltraWebGrid.v10.1, Version=10.1.20101.2039, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
        <script type="text/javascript" id="igClientScript1">  
            var RadGrid1;  
 
            function GetGridObject(sender, eventArgs) {  
                RadGrid1 = sender;  
            }  
            function webImageButtonSearch_Click(oButton, oEvent) {  
                RadGrid1.get_masterTableView().rebind();  
            }  
            function ShowCommissionsForm(employeeID, rowIndex) {  
                var rowControl = RadGrid1.get_masterTableView().get_dataItems()[rowIndex].get_element();  
                RadGrid1.get_masterTableView().selectItem(rowControl, true);  
 
                window.radopen("EmployeeCommissions.aspx?EmployeeID=" + employeeID, "Commissions");  
                return false;  
            }  
            function RemoveFromCampaign(id, rowIndex) {  
                var rowControl = RadGrid1.get_masterTableView().get_dataItems()[rowIndex].get_element();  
                RadGrid1.get_masterTableView().selectItem(rowControl, true);  
                var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");  
                ajaxManager.ajaxRequest("Command=RemoveFromCampaign");  
                return false;  
            }  
            function OnClientClose(oWnd, args) {  
                //get the transferred arguments  
                var arg = args.get_argument();  
                if (arg) {  
                    var argument = "Command=AddToCampaign|" +  
                                   "BaseSalary=" + arg.BaseSalary + "|" +  
                                   "NewCommissionRate=" + arg.NewCommissionRate + "|" +  
                                   "TapCommissionRate=" + arg.TapCommissionRate + "|" +  
                                   "AnnualMembershipFees=" + arg.AnnualMembershipFees + "|" +  
                                   "RequestedCharitableReports=" + arg.RequestedCharitableReports + "|" +  
                                   "RequestedBusinessProfiles=" + arg.RequestedBusinessProfiles + "|" +  
                                   "EnhancedAdvertising=" + arg.EnhancedAdvertising + "|" +  
                                   "ExclusiveAdvertising=" + arg.ExclusiveAdvertising + "|" +  
                                   "SponsoredCharitableReports=" + arg.SponsoredCharitableReports;  
                    var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");  
                    ajaxManager.ajaxRequest(argument);  
                    return false;  
                }  
            }  
        </script> 
    </telerik:RadCodeBlock> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default" /> 
    <table style="width: 100%">  
        <tr> 
            <td style="width: 126px">  
                <telerik:radcombobox ID="RadComboBoxStatus" runat="server" width="90px" 
                    Skin="Vista"   
                    EmptyMessage="All Status">  
                    <Items> 
                        <telerik:RadComboBoxItem runat="server" Selected="True" Text="All Status"   
                            Value="All Status" /> 
                        <telerik:RadComboBoxItem runat="server" Text="Active" Value="Active" /> 
                        <telerik:RadComboBoxItem runat="server" Text="Inactive" Value="Inactive" /> 
                    </Items> 
                </telerik:radcombobox> 
            </td> 
            <td style="width: 236px">  
                <telerik:radcombobox ID="RadComboBoxCity" runat="server" width="200px" 
                    MarkFirstMatch="True" EnableLoadOnDemand="True"   
                    OnItemsRequested="RadComboBoxCity_ItemsRequested" Skin="Vista"   
                    EmptyMessage="All Cities" EnableVirtualScrolling="True" 
                    ShowMoreResultsBox="True" Sort="Ascending" AppendDataBoundItems="True">  
                    <Items> 
                        <telerik:RadComboBoxItem runat="server" Selected="True" Text="All Cities"   
                            Value="All Cities" /> 
                    </Items> 
                </telerik:radcombobox> 
            </td> 
            <td> 
                <igtxt:WebImageButton ID="webImageButtonSearch" runat="server"   
                    ImageDirectory="~/Images"    
                    Text="Search" CausesValidation="False" TabIndex="3"   
                    ToolTip="Click this button to start the search." AutoSubmit="False" > 
                    <ClientSideEvents Click="webImageButtonSearch_Click" /> 
                    <Appearance> 
                        <Image Url="../Images/Search-16x16.png" /> 
                    </Appearance> 
                </igtxt:WebImageButton> 
            </td> 
            <td width="150px">  
            </td> 
            <td> 
                &nbsp;</td> 
        </tr> 
    </table> 
    <table class="style1005">  
        <tr> 
            <td> 
                <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Plus-16x16.png" /> 
                &nbsp;<asp:Label ID="Label8" runat="server" Text="Indicates person is NOT assigned to the campaign."></asp:Label> 
            </td> 
        </tr> 
        <tr> 
            <td> 
                <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/Delete2-16x16.png" /> 
                &nbsp;<asp:Label ID="Label3" runat="server" Text="Indicates the person IS assigned to the campaign."></asp:Label> 
            </td> 
        </tr> 
    </table> 
    <br /> 
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"   
        DataSourceID="LinqDataSource1" Skin="Office2007" GridLines="None"   
        AutoGenerateColumns="False"   
        onitemdatabound="RadGrid1_ItemDataBound" Width="100%" > 
        <MasterTableView DataSourceID="LinqDataSource1">  
            <Columns> 
                <telerik:GridBoundColumn DataField="Name" DefaultInsertValue=""   
                    HeaderText="Worker Name" SortExpression="Name" UniqueName="Name">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Status" DefaultInsertValue=""   
                    HeaderText="Status" SortExpression="Status"   
                    UniqueName="Status">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="City" DefaultInsertValue="" 
                    HeaderText="City" SortExpression="City"   
                    UniqueName="City">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Type" DefaultInsertValue=""   
                    HeaderText="Type" SortExpression="Type" UniqueName="Type">  
                </telerik:GridBoundColumn> 
                <telerik:GridTemplateColumn DefaultInsertValue="" UniqueName="AddRemove" > 
                    <ItemTemplate> 
                        <asp:ImageButton ID="ImageButtonAddRemove" runat="server" 
                                         ImageUrl="~/Images/Plus-16x16.png"   
                                         ToolTip="Add this person to the campaign" /> 
                    </ItemTemplate> 
                    <HeaderStyle Width="20px" /> 
                </telerik:GridTemplateColumn> 
                <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="AddRemove1" Visible="false" 
                    ImageUrl="~/Images/Plus-16x16.png" Text="Add this person to the campaign" UniqueName="AddRemove">  
                    <HeaderStyle Width="20px" /> 
                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /> 
                </telerik:GridButtonColumn> 
                <telerik:GridBoundColumn DataField="ID" DefaultInsertValue="" Visible="false" 
                    HeaderText="ID" ReadOnly="True" SortExpression="ID"   
                    UniqueName="ID" DataType="System.Int32">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="CampaignID" DataType="System.Int32" Visible="false" 
                    DefaultInsertValue="0" HeaderText="CampaignID" SortExpression="CampaignID"   
                    UniqueName="CampaignID" EmptyDataText="0">  
                </telerik:GridBoundColumn> 
            </Columns> 
        </MasterTableView> 
        <ClientSettings>    
            <Selecting AllowRowSelect="true" />    
            <ClientEvents OnGridCreated="GetGridObject"></ClientEvents> 
        </ClientSettings>    
        <PagerStyle Position="TopAndBottom" /> 
    </telerik:RadGrid> 
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server"   
        Behaviors="Move" VisibleStatusbar="False" Skin="Vista">  
        <Windows> 
            <telerik:RadWindow ID="Commissions" runat="server" Title="Employee Commissions" Height="350px" 
                OnClientClose="OnClientClose" 
                Width="400px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" /> 
        </Windows> 
    </telerik:RadWindowManager> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="webImageButtonSearch">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="webImageButtonSearch" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <asp:LinqDataSource ID="LinqDataSource1" runat="server"   
        AutoPage="False" ContextTypeName="CharityCheck.CharityCheckEntities"   
        onselecting="LinqDataSource1_Selecting"   
        TableName="CompanySet">  
    </asp:LinqDataSource> 
    <asp:SqlDataSource ID="SqlDataSourceUsers" runat="server"   
        ConnectionString="<%$ ConnectionStrings:CharityCheckConnectionString %>"   
        SelectCommand="SELECT Employees.Name, Employees.Status, Cities.Name AS City, Employees.ID, Employees.Type, CampaignEmployee.CampaignID FROM Employees LEFT OUTER JOIN CampaignEmployee ON Employees.ID = CampaignEmployee.EmployeeID LEFT OUTER JOIN Cities ON Employees.City = Cities.Name WHERE (Employees.Status LIKE @StatusParam) AND (Cities.Name LIKE @CityParam) ORDER BY Employees.Name">  
        <SelectParameters> 
            <asp:Parameter Name="StatusParam" /> 
            <asp:Parameter Name="CityParam" /> 
        </SelectParameters> 
    </asp:SqlDataSource> 
</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.SqlClient;  
using System.Configuration;  
using System.ComponentModel;  
using System.Diagnostics;  
using Infragistics.WebUI.UltraWebGrid;  
using Infragistics.WebUI.WebDataInput;  
using Telerik.Web.UI;  
 
namespace CharityCheck.Admin  
{  
    public partial class ContractorsList : System.Web.UI.Page  
    {
        #region Properties  
        [Browsable(false)]  
        public int CampaignID  
        {  
            get 
            {  
                object obj2 = this.ViewState["CampaignID"];  
                return (obj2 != null) ? (int)obj2 : 0;  
            }  
            set 
            {  
                this.ViewState["CampaignID"] = value;  
            }  
        }
        #endregion  
 
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!IsPostBack)  
            {  
                CampaignID = Convert.ToInt32(Session["Contractors:CampaignID"]);  
            }  
        }  
 
        protected void RadComboBoxCity_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)  
        {  
            const int ItemsPerRequest = 10;  
 
            DataTable data = GetData(e.Text);  
 
            int itemOffset = e.NumberOfItems;  
            int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);  
            e.EndOfItems = endOffset == data.Rows.Count;  
 
            for (int i = itemOffset; i < endOffset; i++)  
            {  
                RadComboBoxCity.Items.Add(new RadComboBoxItem(data.Rows[i]["Name"].ToString(), data.Rows[i]["Name"].ToString()));  
            }  
 
            e.Message = GetStatusMessage(endOffset, data.Rows.Count);  
        }  
 
        private static DataTable GetData(string text)  
        {  
            String strQuery = String.Format("SELECT Name,ID FROM Cities " +  
                                            "WHERE Name LIKE '{0}%' " +  
                                            "ORDER BY Name",  
                                            text);  
 
            SqlDataAdapter adapter = new SqlDataAdapter(strQuery,  
                ConfigurationManager.ConnectionStrings["CharityCheckConnectionString"].ConnectionString);  
 
            DataTable data = new DataTable();  
            adapter.Fill(data);  
 
            return data;  
        }  
 
        private static string GetStatusMessage(int offset, int total)  
        {  
            if (total <= 0)  
                return "No matches";  
 
            return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total);  
        }  
 
        protected void webImageButtonSearch_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)  
        {  
            Search(RadComboBoxCity.Text, RadComboBoxStatus.Text);  
        }  
 
        protected void Search(string strCity, string strStatus)  
        {  
            SqlDataSourceUsers.SelectParameters["CityParam"].DefaultValue = (strCity == "All Cities") ? "%" : strCity;  
            SqlDataSourceUsers.SelectParameters["StatusParam"].DefaultValue = (strStatus == "All Status") ? "%" : strStatus;  
            RadGrid1.DataBind();  
        }  
 
        protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
        {  
            if (e.Item is GridDataItem)  
            {  
                ImageButton button = e.CommandSource as ImageButton;  
                GridDataItem item = RadGrid1.Items[e.Item.ItemIndex];  
                if (button != null)  
                {  
                    int nID = Convert.ToInt32(item["ID"].Text);  
 
                    CharityCheckEntities entities = new CharityCheckEntities();  
                    CampaignEmployee intersect = null;  
                    switch (e.CommandName)  
                    {  
                        case "Add":  
                            intersect = new CampaignEmployee();  
                            intersect.CampaignID = CampaignID;  
                            intersect.EmployeeID = nID;  
                            entities.AddToCampaignEmployeeSet(intersect);  
 
                            button.CommandName = "Remove";  
                            button.ImageUrl = "/Images/Delete2-16x16.png";  
                            item.Selected = true;  
                            break;  
                        case "Remove":  
                            intersect = (from i in entities.CampaignEmployeeSet  
                                         where i.CampaignID == CampaignID &&  
                                               i.EmployeeID == nID  
                                         select i).FirstOrDefault();  
                            entities.DeleteObject(intersect);  
 
                            button.CommandName = "Add";  
                            button.ImageUrl = "/Images/Plus-16x16.png";  
                            item.Selected = true;  
                            break;  
                    }  
                    entities.SaveChanges();  
                }  
            }  
        }  
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridDataItem)  
            {  
                GridDataItem item = e.Item as GridDataItem;  
                if (item == null)  
                    return;  
 
                ImageButton button = (ImageButton)e.Item.FindControl("ImageButtonAddRemove");  
                //ImageButton button1 = item["AddRemove1"].Controls[0] as ImageButton;  
                if (Convert.ToInt32(item["CampaignID"].Text) == 0)  
                {  
                    //button1.CommandName = "Add";  
                    //button1.ToolTip = "Add this person to the campaign";  
                    //button1.ImageUrl = "/Images/Plus-16x16.png";  
                    button.CommandName = "Add";  
                    button.ToolTip = "Add this person to the campaign";  
                    button.ImageUrl = "/Images/Plus-16x16.png";  
                    button.Attributes["onclick"] = String.Format("return ShowCommissionsForm('{0}','{1}');",  
                                                                    item["ID"].Text, e.Item.ItemIndex);  
                }  
                else 
                {  
                    //button1.CommandName = "Remove";  
                    //button1.ToolTip = "Remove this person from the campaign";  
                    //button1.ImageUrl = "/Images/Delete2-16x16.png";  
                    button.CommandName = "Remove";  
                    button.ToolTip = "Remove this person from the campaign";  
                    button.ImageUrl = "/Images/Delete2-16x16.png";  
                    button.Attributes["onclick"] = String.Format("return RemoveFromCampaign('{0}','{1}');",  
                                                                    item["ID"].Text, e.Item.ItemIndex);  
                }  
            }  
        }  
 
        protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)  
        {  
            String strCity = RadComboBoxCity.SelectedValue;  
            String strStatus = RadComboBoxStatus.SelectedValue;  
 
            CharityCheckEntities entities = new CharityCheckEntities();  
            var data = from employee in entities.EmployeeSet  
                       let campaignemployee = (from ce in entities.CampaignEmployeeSet  
                                               where ce.EmployeeID == employee.ID && ce.CampaignID == CampaignID  
                                               select ce).FirstOrDefault()  
                       let cities = entities.CitiesSet.Where(c => c.Name == employee.City).FirstOrDefault()  
                       where (strCity == "All Cities" ? true : employee.City.StartsWith(strCity)) &&  
                             (strStatus == "All Status" ? true : (employee.Status == strStatus)) &&  
                             employee.Name != "admin" 
                       orderby employee.Name  
                       select new 
                       {  
                           employee.ID,  
                           employee.Name,  
                           employee.Status,  
                           employee.Type,  
                           City = (cities == null) ? String.Empty : cities.Name,  
                           CampaignID = (campaignemployee == null) ? 0 : campaignemployee.CampaignID  
                       };  
            e.Result = data;  
            e.Arguments.TotalRowCount = data.Count();  
        }  
 
        public void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)  
        {  
            GridDataItem item = RadGrid1.SelectedItems[0] as GridDataItem;  
            if (item != null)  
            {  
                CharityCheckEntities entities = new CharityCheckEntities();  
                CampaignEmployee intersect = null;  
 
                ImageButton button = (ImageButton)item.FindControl("ImageButtonAddRemove");  
                int nID = Convert.ToInt32(item["ID"].Text);  
                String[] args = e.Argument.Split('|');  
                switch (args[0].Split('=')[1])  
                {  
                    case "AddToCampaign":  
                        intersect = new CampaignEmployee();  
                        intersect.CampaignID = CampaignID;  
                        intersect.EmployeeID = nID;  
                        entities.AddToCampaignEmployeeSet(intersect);  
                        for (int n = 1; n != args.Length; n++)  
                        {  
                            String[] values = args[n].Split('=');  
                            String strField = values[0];  
                            String strValue = values[1];  
                            switch (strField)  
                            {  
                                case "BaseSalary":  
                                    intersect.BaseSalary = Convert.ToDecimal(strValue);  
                                    break;  
                                case "NewCommissionRate":  
                                    intersect.NewCommissionRate = Convert.ToSingle(strValue);  
                                    break;  
                                case "TapCommissionRate":  
                                    intersect.TapCommissionRate = Convert.ToSingle(strValue);  
                                    break;  
                                case "AnnualMembershipFees":  
                                    intersect.AnnualMembershipFees = Convert.ToSingle(strValue);  
                                    break;  
                                case "RequestedCharitableReports":  
                                    intersect.RequestedCharitableReports = Convert.ToSingle(strValue);  
                                    break;  
                                case "RequestedBusinessProfiles":  
                                    intersect.RequestedBusinessProfiles = Convert.ToSingle(strValue);  
                                    break;  
                                case "EnhancedAdvertising":  
                                    intersect.EnhancedAdvertising = Convert.ToSingle(strValue);  
                                    break;  
                                case "ExclusiveAdvertising":  
                                    intersect.ExclusiveAdvertising = Convert.ToSingle(strValue);  
                                    break;  
                                case "SponsoredCharitableReports":  
                                    intersect.SponsoredCharitableReports = Convert.ToSingle(strValue);  
                                    break;  
                            }  
                        }  
                        entities.AddToCampaignEmployeeSet(intersect);  
                        break;  
                    case "RemoveFromCampaign":  
                        intersect = (from i in entities.CampaignEmployeeSet  
                                        where i.CampaignID == CampaignID &&  
                                            i.EmployeeID == nID  
                                        select i).FirstOrDefault();  
                        if (intersect != null)  
                            entities.DeleteObject(intersect);  
                        break;  
                }  
                entities.SaveChanges();  
                RadGrid1.Rebind();  
            }  
        }  
    }  
}  
 
Tags
Grid
Asked by
John Fetherolf
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
John Fetherolf
Top achievements
Rank 1
rcbarth
Top achievements
Rank 1
Yavor
Telerik team
HHH
Top achievements
Rank 1
Prangadj
Top achievements
Rank 1
altaf
Top achievements
Rank 1
David Simmonds
Top achievements
Rank 1
Share this question
or