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> |