Inge Wandsvik
Top achievements
Rank 1
Inge Wandsvik
asked on 21 May 2008, 12:54 PM
Im having serious problems in my RadGrid1_UpdateCommand. I am using a RadGrid with a FormTemplate for editing values. In my FormTemplate I have a TextBox with id "txtValue". No matter what I do in my RadGrid1_UpdateCommand, I can not find this TextBox and get it's Text. I have tried TryCast and DirectCast, and I have tried the same way as I have been using in older RadGrids for ASP.Net (none Ajax), with no luck. I only get a NullReferenceException. I have also tried to define a string variable with the value "NewValue" just to test the code, but now I get an exception that say that IsInEditMode must be set to TRUE. How can I get the Text from my TextBox without exceptions, and how can I avoid getting an IsInEditMode must be set to True??? I have spent 2 days with this problem now, and the documentation of the RadGrid for Ajax doesnt say anything about how to use FormTemplate and RadGrid1_UpdateCommand.
7 Answers, 1 is accepted
0
Hi Inge,
Generally controls in FormTemplate can be found using e.Item,FindControl() in UpdateCommand. Can you show us an example which illustrates the scenario at your end?
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Generally controls in FormTemplate can be found using e.Item,FindControl() in UpdateCommand. Can you show us an example which illustrates the scenario at your end?
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Inge Wandsvik
Top achievements
Rank 1
answered on 21 May 2008, 01:29 PM
This is what I'm doing in the RadGrid1_UpdateCommand that throw a NullReferenceException:
Dim myTextBox As TextBox = CType(e.Item.FindControl("txtValue"), TextBox)
Dim myText As String = myTextBox.Text
myTextBox has value Nothing, so my next line throw the exception.
I have also tried the following, which give me an exception that say IsInEditMode must be set to True:
Dim myText As String = "MyValue"
0
Hello Inge,
Please open a support ticket with an example where we can reproduce this. I will review your code and I will get back to you with more info.
Best wishes,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Please open a support ticket with an example where we can reproduce this. I will review your code and I will get back to you with more info.
Best wishes,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Shinu
Top achievements
Rank 2
answered on 22 May 2008, 07:09 AM
Hi,
Can you give a try with the followimg code snippet.
CS:
Thanks
Shinu.
Can you give a try with the followimg code snippet.
CS:
| protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditFormItem editedItem = (GridEditFormItem)e.Item; |
| //Access the textbox from the edit form template and store the values in string variables. |
| TextBox txtbx = (TextBox) editedItem.FindControl("txtValue"); |
| string strtxt= txtbx.Text.ToString(); |
| } |
Thanks
Shinu.
0
Inge Wandsvik
Top achievements
Rank 1
answered on 22 May 2008, 08:28 AM
Thanks Shinu, but your code didn't work well, so I had to modify it a little. Here is my modified code (e.item is GridDataItem and NOT GridEditFormItem,)
Now the code works, but no matter what I do I get an exception that say "Only items with IsInEditMode set to true can be updated". I have installed the latest version of the RadGrid for AJAX (2008.1.515.35) but still the same problem. I have even tried to remove all the code in the UpdateCommand section, and I still get the same error.This is driving me crazy...
| Dim editedItem As GridDataItem = DirectCast(e.Item, GridDataItem) |
| Dim frmItem As GridEditFormItem = editedItem.EditFormItem |
| Dim txtbx As TextBox = DirectCast(frmItem.FindControl("txtValue"), TextBox) |
| Dim strtxt As String = txtbx.Text.ToString() |
Now the code works, but no matter what I do I get an exception that say "Only items with IsInEditMode set to true can be updated". I have installed the latest version of the RadGrid for AJAX (2008.1.515.35) but still the same problem. I have even tried to remove all the code in the UpdateCommand section, and I still get the same error.This is driving me crazy...
0
Princy
Top achievements
Rank 2
answered on 22 May 2008, 09:21 AM
Hi,
I have found the following forum links which discuss a similar error. Go through it and see whether it is helpful.
Only items with IsInEditMode set to true can be updated
RadGrid Cancel command
CommandName="UpdateEdited" does not work
Princy.
I have found the following forum links which discuss a similar error. Go through it and see whether it is helpful.
Only items with IsInEditMode set to true can be updated
RadGrid Cancel command
CommandName="UpdateEdited" does not work
Princy.
0
Inge Wandsvik
Top achievements
Rank 1
answered on 22 May 2008, 09:54 AM
Thanks, Princy. I solved the problem now. This is the solution for me:. AllowAutomaticUpdates="False".
