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

UpdateCommand and getting editedItem

1 Answer 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 2
Alexander asked on 11 Aug 2009, 03:29 AM
I have wasted a lot of time today because I did not fully understand the control hiarcy of the RadGrid.
 My problem was that I were not able to get the values from the editedItem controls.

My grid has a  GridTemplateColumn like this 


<
telerik:GridTemplateColumn UniqueName="doc_name_org" HeaderText="Document">

 

<HeaderStyle CssClass="colored_header" Width="40%" />

 

 

 

<ItemStyle CssClass="colored" Width="40%" />

 

 

 

<ItemTemplate>

 

 

 

<asp:ImageButton ID="lnk_doc_name_org_img" Style="border: 0px; vertical-align: middle;" runat="server" />

 

 

 

<asp:HyperLink ID="lnk_doc_name_org_txt" runat="server"></asp:HyperLink>

 

 

 

</ItemTemplate>

 

 

 

<EditItemTemplate>

 

 

 

 <asp:TextBox ID="txtFileName" CssClass="small" Style="float: left" runat="server" Text="" Width="60%"></asp:TextBox>

 

 

 

 <input type="button" style="float: right" causesvalidation="false" id="btnGetExtraDoc" runat="server" class="button_small" value="Get document" />

 

 

</EditItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 


Handling the ItemTemplate was ok, but the EditItemTemplate was a bit more tricky.
Every example I came across used this methode to get the value from the textbox txtFileName

 

 

Dim DocName As String = TryCast(editedItem("doc_name_org").Controls(0), TextBox).Text

But of course it was not that simple. It turned out that I had to use .Controls(1) to get the textbox value.

 


I find this a bit confusing because I actually would expect the textbox to be control(0) and the button to be control(1)....
Any explenations for this? Is control(0) the ItemTemplate and Control(1) the EditTemplate?
If so, I must have missed this explenation somewhere....

To remove the posibility of messing this up later on I figured I should use another approach that does not relay on me to get the index right.

So, the following line accomplishes the same result, but more failsafe. I can add/remove controls without any damage.

Dim
DocName2 As String = TryCast(e.Item.FindControl("txtFileName"), TextBox).Text

I think the examples for Telerik Controls should also demonstrate more complex implementations and give explenations for them, not just basic implementations.

Hope this helps someone.

regards
Alexander

 

 

 

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 11 Aug 2009, 11:03 AM
Hello Alexander,

Please,  note that the examples you have looked at, where the first control in the edit template turned out to be the textbox, concern GridBoundColumns or GridTemplateColumns with just a single textbox in them. When a GridTemplateColumn with more controls in the EditItemTemplate is concerned, of course, the correct approach is to use the FindControl method since in this case you have the ID of the corresponding control while in the former - the ID of the textbox is known only to the ASP.NET runtime.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Alexander
Top achievements
Rank 2
Answers by
Tsvetoslav
Telerik team
Share this question
or