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

[Solved] EditForm Only Returning SavedValue

1 Answer 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Garry
Top achievements
Rank 1
Garry asked on 11 Mar 2008, 07:59 PM

I have a fairly simple grid that onyl has 2 columns in it, Key and Value. It is bound to an ArrayList that contains a struct object. Everything thing works as expected, but when I try and get the value from the EditForm it always returns the original value. Not the value that the user has input. I've tried to approach this from a few different examples on the Website, but I have had no luck thus far. Any ideas on how to get the new value? Below is my code.

Thanks!

Code Behind

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;  
 
 
public partial class Controls_Settings_AppSettings : System.Web.UI.UserControl  
{  
    TelerikSkinning glb = new TelerikSkinning();  
    string skinName = String.Empty;  
 
    public struct appKeys  
    {  
        string mKey, mValue;  
 
        public appKeys(string key, string value)  
        {  
            this.mKey = key;  
            this.mValue = value;  
        }  
 
        public string Key  
        {  
            get 
            {  
                return mKey;  
            }  
            set 
            {  
                mKey = value;  
            }  
        }  
        public string Value  
        {  
            get 
            {  
                return mValue;  
            }  
            set 
            {  
                mValue = value;  
            }  
        }  
    }  
 
    protected void Page_Load(object sender, EventArgs e)  
    {  
        if (!Page.IsPostBack)  
        {  
            SetTelerikTheme();  
        }  
        SetGridSource();  
    }  
 
    protected void SetGridSource()  
    {  
        ArrayList keyList = new ArrayList();  
        foreach (string setting in ConfigurationManager.AppSettings.Keys)  
        {  
            appKeys key = new appKeys(setting, ConfigurationManager.AppSettings[setting]);  
            keyList.Add(key);  
        }  
 
        gridSettings.DataSource = keyList;  
        gridSettings.DataBind();  
    }  
 
    protected void SetTelerikTheme()  
    {  
        string xmlFile = Server.MapPath("~/App_Themes/" + Page.Theme + "/SkinSettings.xml");  
 
        skinName = glb.GetTextBoxSkin(xmlFile);  
    }  
 
    protected void gridSettings_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
    {  
        //Get Configuration  
        Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");  
 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))  
        {  
            GridEditableItem edititem = (GridEditableItem)e.Item;  
            TextBox txtKey = (TextBox)edititem["Key"].Controls[0];  
            string strKey = txtKey.Text;  
            TextBox txtValue = (TextBox)edititem["Value"].Controls[0];  
            string strVal = txtValue.Text;  
            //Set Value  
            KeyValueConfigurationElement key = config.AppSettings.Settings[strKey];  
            key.Value = strVal;  
        }           
 
        // Save the configuration file.  
        config.Save();  
 
        // Force a reload of the changed section.  
        ConfigurationManager.RefreshSection("appSettings");  
    }  

User Control

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AppSettings.ascx.cs" Inherits="Controls_Settings_AppSettings" %> 
<%@ Register Assembly="Telerik.Web.UI, Version=2007.3.1314.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" 
    Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<telerik:RadGrid ID="gridSettings" runat="server" AllowSorting="True" AutoGenerateColumns="False" 
    GridLines="None" Skin="Office2007" OnUpdateCommand="gridSettings_UpdateCommand">  
    <GroupPanel ID="GroupPanel" Style="width: 100%;">  
    </GroupPanel><ExportSettings>  
        <Pdf FontType="Subset" PaperSize="Letter" /> 
        <Excel Format="Html" /> 
    </ExportSettings> 
    <MasterTableView CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" 
        Dir="LTR" Frame="Border" TableLayout="Auto" AllowAutomaticUpdates="false" AllowAutomaticDeletes="false" 
        AllowAutomaticInserts="false" EditMode="InPlace" DataKeyNames="Key">  
        <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
            Visible="False">  
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
            Resizable="False" Visible="False">  
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Key" FilterListOptions="VaryByDataType" 
                ForceExtractValue="Always" HeaderText="Key" SortExpression="Key" UniqueName="Key">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Value" FilterListOptions="VaryByDataType" 
                ForceExtractValue="Always" HeaderText="Value" SortExpression="Value" UniqueName="Value">  
            </telerik:GridBoundColumn> 
            <telerik:GridEditCommandColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">  
            </telerik:GridEditCommandColumn> 
            <telerik:GridButtonColumn CommandName="Delete" CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
                Text="Delete" UniqueName="column">  
            </telerik:GridButtonColumn> 
        </Columns> 
        <EditFormSettings> 
            <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">  
            </EditColumn> 
        </EditFormSettings> 
    </MasterTableView></telerik:RadGrid> 
 

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 14 Mar 2008, 02:55 PM
Hello Garry Clark,

From your code snippets I see that you use simple binding invoking the DataBind() method of the grid. Note that operations like data editing, filtering, etc. require advanced binding through the NeedDataSource event or data source control:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/NeedDataSource/DefaultCS.aspx
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/AllEditableColumns/DefaultCS.aspx

Please modify your code accordingly to avoid the unexpected results. Additional information about how to update grid records you can find here:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/EditModes/DefaultCS.aspx
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/ExtractValues/DefaultCS.aspx
http://www.telerik.com/help/radcontrols/prometheus/?grdUpdatingInPlaceAndEditForms.html

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Garry
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or