Please ignore my ignorance as I'm new to this technology as well as the controls here.
Following is my scenario and what i'm trying to achieve:
My RadGrid should load, a custom column to represent the edit column. Once you click on it, using ModelPopupExtender I am pulling out the row item data into the form and once i hit the update button, it should update the record in db as well as update the grid using ajax.
Following is the poc i developed to mimic my original code. Everything works fine if i disable the rad ajax feature. But if i enable this, my popup loads, but its always empty.
Not able to figure out the right properties to set for ajaxifying the grid and the popup item. Or what is the real problem behind this.
Please refer to the below code and let me know where and what I'm missing here.
Some info abt the code:
1. The grid loads up directly using the nortwind.mdf file and the datasource mentioned in the aspx page itself.
2. The 2 columns of edit and delete are thr. Delete calls its native delete method available with radgrid.
3. The edit calls a custom edit which is overriden in its .cs class.
4. This internally calls the modelextender popup and shows it with the row level information to be edited.
5. The update button on the popup triggers a grid update event so that the data can be saved and the grid reloads automatically.
Waiting eagerly for the reply.
Thanks.
ASPX File:
C# Code:
Web.Config:
Following is my scenario and what i'm trying to achieve:
My RadGrid should load, a custom column to represent the edit column. Once you click on it, using ModelPopupExtender I am pulling out the row item data into the form and once i hit the update button, it should update the record in db as well as update the grid using ajax.
Following is the poc i developed to mimic my original code. Everything works fine if i disable the rad ajax feature. But if i enable this, my popup loads, but its always empty.
Not able to figure out the right properties to set for ajaxifying the grid and the popup item. Or what is the real problem behind this.
Please refer to the below code and let me know where and what I'm missing here.
Some info abt the code:
1. The grid loads up directly using the nortwind.mdf file and the datasource mentioned in the aspx page itself.
2. The 2 columns of edit and delete are thr. Delete calls its native delete method available with radgrid.
3. The edit calls a custom edit which is overriden in its .cs class.
4. This internally calls the modelextender popup and shows it with the row level information to be edited.
5. The update button on the popup triggers a grid update event so that the data can be saved and the grid reloads automatically.
Waiting eagerly for the reply.
Thanks.
ASPX File:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Grid.aspx.cs" Inherits="Grid" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="mpe" %><html xmlns="http://www.w3.org/1999/xhtml"><body> <form id="form1" runat="server"> <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> <div> <p> View Grid</p> </div> <div> <telerik:RadAjaxManager ID="RadManager" runat="server" EnableAJAX="true"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="updateButton"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" DataSourceID="SessionDataSource2" HorizontalAlign="Center" AllowAutomaticDeletes="True" OnItemCommand="radGrid_ItemCommand" PageSize="5" AutoGenerateColumns="False" GridLines="None"> <MasterTableView DataSourceID="SessionDataSource2" DataKeyNames="EmployeeID"> <Columns> <telerik:GridTemplateColumn HeaderText="Edit" HeaderStyle-Width="50"> <ItemTemplate> <asp:ImageButton ID="imgbtn" ImageUrl="Edit.jpg" AlternateText="Edit Record" runat="server" Width="24" Height="24" CommandName="CustomEdit" /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridClientDeleteColumn HeaderText="Delete" HeaderStyle-Width="50"> <FilterTemplate> <asp:ImageButton ID="imgbtnForDelete" ImageUrl="Delete.jpg" runat="server" Width="24" Height="24" /> </FilterTemplate> </telerik:GridClientDeleteColumn> <telerik:GridBoundColumn UniqueName="EmployeeID" HeaderText="Employee ID" DataField="EmployeeID" /> <telerik:GridBoundColumn UniqueName="LastName" HeaderText="Last Name" DataField="LastName" /> <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="FirstName"> </telerik:GridBoundColumn> </Columns> <PagerStyle Mode="NextPrevAndNumeric" /> </MasterTableView> </telerik:RadGrid> <div> <asp:Label ID="lblresult" runat="server" /> </div> <asp:Button ID="ppButton" runat="server" Style="display: none" /> <mpe:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="ppButton" PopupControlID="pnlpopup" CancelControlID="cancelButton" BackgroundCssClass="modalBackground" /> <asp:Panel ID="pnlpopup" runat="server" Height="100px" Width="480px" Style="display: none; background: lightGrey;"> <table border = "1" align="center"><tr><td>Text for popup</td><td>EmpID: <asp:Label ID="employeeID" runat="server" /></td></tr> <tr><td>FName: <asp:TextBox ID="firstName" runat="server" /></td><td>LName: <asp:TextBox ID="lastName" runat="server" /></td></tr> <tr><td><asp:Button ID="updateButton" runat="server" Text="Update" OnClick="btnUpdate_Click"/></td><td><asp:Button ID="cancelButton" runat="server" Text="Cancel"/></td></tr></table> </asp:Panel> </div> <asp:SqlDataSource ID="SessionDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" ProviderName="System.Data.SqlClient" DeleteCommand="DELETE FROM [Employees] WHERE [EmployeeID] = ?" InsertCommand="INSERT INTO [Employees] ([EmployeeID], [LastName], [FirstName]) VALUES (?, ?, ?)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [EmployeeID], [LastName], [FirstName] FROM [Employees]" UpdateCommand="UPDATE [Employees] SET [LastName] = ?, [FirstName] = ? WHERE [EmployeeID] = ? "> <UpdateParameters> <asp:Parameter Name="lastName" Type="String" /> <asp:Parameter Name="firstName" Type="String" /> <asp:Parameter Name="employeeID" Type="Int32" /> </UpdateParameters> <DeleteParameters> <asp:Parameter Name="original_EmployeeID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="EmployeeID" Type="Int32" /> <asp:Parameter Name="LastName" Type="String" /> <asp:Parameter Name="FirstName" Type="String" /> </InsertParameters> </asp:SqlDataSource> </form></body></html>C# Code:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Drawing;using Telerik.Web.UI;public partial class Grid : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void radGrid_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName == "CustomEdit") { GridDataItem item = RadGrid1.MasterTableView.Items[e.Item.ItemIndex]; employeeID.Text = item.GetDataKeyValue("EmployeeID").ToString(); firstName.Text = (string)item["FirstName"].Text; lastName.Text = (string)item["LastName"].Text; this.ModalPopupExtender1.Show(); } } protected void btnUpdate_Click(object sender, EventArgs e) { GridEditableItem editedItem = null; foreach (GridEditFormItem dataItem in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)) { if (employeeID.Text.Equals(dataItem.GetDataKeyValue("EmployeeID").ToString())) { editedItem = dataItem; editedItem.UpdateValues(firstName.Text); editedItem.UpdateValues(lastName.Text); editedItem.FireCommandEvent("Update", null); editedItem.Edit = false; break; } } RadGrid1.MasterTableView.ClearEditItems(); this.ModalPopupExtender1.Hide(); lblresult.Text = "Emp Id: " +employeeID.Text + " Updated Successfully"; lblresult.ForeColor = Color.Green; RadGrid1.Rebind(); }}Web.Config:
<?xml version="1.0"?><!-- Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.Net\Framework\v2.x\Config --><configuration> <configSections> <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /> <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> </sectionGroup> </sectionGroup> </sectionGroup> </configSections> <appSettings /> <connectionStrings> <add name="NorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/> </connectionStrings> <system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. --> <compilation debug="true"> <assemblies> <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> </assemblies> </compilation> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows" /> <!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. --> <pages> <controls> <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" /> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </controls> </pages> <httpHandlers> <remove verb="*" path="*.asmx" /> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" /> <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" /> </httpHandlers> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </httpModules> </system.web> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5" /> <providerOption name="WarnAsError" value="false" /> </compiler> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5" /> <providerOption name="OptionInfer" value="true" /> <providerOption name="WarnAsError" value="false" /> </compiler> </compilers> </system.codedom> <!-- The system.webServer section is required for running ASP.NET AJAX under Internet Information Services 7.0. It is not necessary for previous version of IIS. --> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules> <remove name="ScriptModule" /> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </modules> <handlers> <remove name="WebServiceHandlerFactory-Integrated" /> <remove name="ScriptHandlerFactory" /> <remove name="ScriptHandlerFactoryAppServices" /> <remove name="ScriptResource" /> <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" /> </handlers> </system.webServer> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /> </dependentAssembly> </assemblyBinding> </runtime></configuration>