Accessing DataItem and EditItemTemplate controls from OnItemEditing

3 posts, 0 answers
  1. Bruno
    Bruno avatar
    16 posts
    Member since:
    May 2008

    Posted 19 Nov 2009 Link to this post

    Given a ListView with an ItemTemplate, InsertItemTemplate, and EditItemTemplate, how can I access the controls in the EditItemTemplate before they are first displayed?

    <telerik:RadListView ID="ContactsList" runat="server" DataSourceID="ContactsDataSource"   

    ContactsDataSource is a LinqDataSource with EnableUpdate=true

                    <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.Name" ) %>'   
                            ForeColor="Blue" CommandName="Edit" CausesValidation="false" /> 

    protected void ContactsList_ItemEditing(object sender, RadListViewCommandEventArgs e)  
            if (e.ListViewItem.ItemType == RadListViewItemType.DataItem)  
                RadListViewDataItem dataItem = (RadListViewDataItem)e.ListViewItem;  

    Here, dataItem.DataItem is null, e.ListViewItem.FindControl() only finds controls in the ItemTemplate and not the EditItemTemplate and e.ListViewItem.IsInEditMode is false.

    There is a LinkButton in the EditItemTemplate I need to access and modify before the edit form is shown to the user.
  2. Rosen
    Rosen avatar
    3216 posts

    Posted 20 Nov 2009 Link to this post

    Hi Bruno,

    At the point of which ItemEditing event is raised, the RadListView is actually not yet switch to edit mode. Therefore a better place to access controls from EditTemplate is inside ItemCreated event as shown bellow:

    protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
          if (e.Item is RadListViewEditableItem && e.Item.IsInEditMode)
              var myControl = e.Item.FindControl("MyControlID");

    Sincerely yours,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft R3 2016 release webinar banner
  4. Erik
    Erik avatar
    1 posts
    Member since:
    Sep 2010

    Posted 10 Oct 2010 Link to this post






    protected void rlv_ProductFile_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)





    if (e.Item.ItemType.Equals(RadListViewItemType.DataItem) || e.Item.ItemType.Equals(RadListViewItemType.AlternatingItem))





    RadBinaryImage DataImage = (RadBinaryImage)e.Item.FindControl("DataImage");




    RadListViewDataItem dataItem = ((RadListViewDataItem)e.Item).DataItem;






    give this compiler error :
    Error 1 Cannot implicitly convert type 'object' to 'Telerik.Web.UI.RadListViewDataItem'. An explicit conversion exists (are you missing a cast?) D:\Dev\KeepOnTrack\WebUserControls\Shop\ShowProductFile.ascx.cs 40 48 KeepOnTrack

    please help

Back to Top