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

RadGrid Can't access edited values on post back

1 Answer 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
anteneh
Top achievements
Rank 1
anteneh asked on 21 Jun 2011, 05:22 PM
Hello there,

I am using the radGrid and am updating values using edit forms.
 On the code behind I couldn't get the updated values that i entered in the text-boxes. It always shows the old values. I have tried two approaches. using the ExtractValuesFromItem(dictonaryObject, editedItem) method and Fetching the data from each edited field individually through the auto-generated column editors, which both seems not to work. here is the markup for the grid and the code behind.
I would appreciate if somebody can help me out with this issue. I only have a day.

 



<
tlrk:RadGrid ID="tlrkExpGrid" runat="server" CellSpacing="0" 

GridLines="None" AutoGenerateColumns = "False"  

OnUpdateCommand = "expDG_RowUpdating" >

 <MasterTableView commanditemdisplay="Top" EditMode = "EditForms" DataKeyNames = "ex_code">

 <Columns>
<tlrk:GridEditCommandColumn ButtonType="LinkButton" UniqueName="EditCommandColumn">

 <ItemStyle CssClass="MyImageButton"/>

 </tlrk:GridEditCommandColumn>

 <tlrk:GridBoundColumn DataField="ex_code" HeaderText="Code"  UniqueName="ex_code" >

 </tlrk:GridBoundColumn>

 <tlrk:GridBoundColumn DataField="ex_name" HeaderText="Name" UniqueName="ex_name" >

 </tlrk:GridBoundColumn>

 <tlrk:GridBoundColumn DataField="DUNS" HeaderText="DUNS" UniqueName="DUNS" >

 </tlrk:GridBoundColumn>

 <tlrk:GridBoundColumn DataField="email" HeaderText="Email" UniqueName="email" ColumnEditorID = "emailEditor">

 </tlrk:GridBoundColumn>

 <tlrk:GridButtonColumn ConfirmText="Delete this Exporter?" ConfirmDialogType="RadWindow"

 ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"

 UniqueName="DeleteColumn">

 <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />

</tlrk:GridButtonColumn>

 </Columns>

 <EditFormSettings>

 <EditColumn UniqueName="EditCommandColumn" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>

 </EditFormSettings>

  </MasterTableView>

 </tlrk:RadGrid>

 
protected

void expDG_RowUpdating(object source,Telerik.Web.UI.GridCommandEventArgs e)

 {

 GridEditableItem editedItem = e.Item as GridEditableItem;

 string expCode = (editedItem["ex_code"].Controls[0] as TextBox).Text;

 string expName = (editedItem["ex_name"].Controls[0] as TextBox).Text;

 string duns = (editedItem["DUNS"].Controls[0] as TextBox).Text;

string email = (editedItem["email"].Controls[0] as TextBox).Text;

//this is the first approach

 Hashtable newValues = new Hashtable();

 e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

 

//this was the second approach trying to loop through each editor 

GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("email");

TextBox t = editor.TextBoxControl;

string ee = t.Text;

GridEditableItem editedItem = e.Item as GridEditableItem;

 GridEditManager editMan = editedItem.EditManager;

  

 

 foreach( GridColumn column in e.Item.OwnerTableView.RenderColumns )

 {

 if ( column is IGridEditableColumn )

 {

  IGridEditableColumn editableCol = (column as IGridEditableColumn);

  if ( editableCol.IsEditable )

 {

  IGridColumnEditor editor = editMan.GetColumnEditor( editableCol );

  string editorType = editor.ToString();

  string editorText = "unknown";

  object editorValue = null;

 if ( editor is GridTextColumnEditor )

 {

 editorText = (editor as GridTextColumnEditor).Text;

 editorValue = (editor as GridTextColumnEditor).Text;

  }

}

}

}

 

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 24 Jun 2011, 07:57 AM
Hello anteneh,

You properly found which are the both possible approaches for extracting new values on UpdateCommand:
Using Column Editors
Using ExtractValuesFromItem()

However can you elaborate on how you are binding the grid? I would suggest that you do that through the NeedDataSource event instead of using simple data-binding. See what are the differences below:
http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html
http://www.telerik.com/help/aspnet-ajax/grid-simple-data-binding.html

All the best,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
anteneh
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or