UpdateCommand and getting editedItem

2 posts, 0 answers
  1. Alexander
    Alexander avatar
    14 posts
    Member since:
    Oct 2007

    Posted 10 Aug 2009 Link to this post

    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

     

     

     

  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 11 Aug 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top