Accessing ListView Item Being Edited

2 posts, 0 answers
  1. Ramjet
    Ramjet avatar
    51 posts
    Member since:
    Jul 2009

    Posted 09 Jun 2013 Link to this post

    I have a RadListView that binds and displays data correctly. In the ItemTemplate there is an edit button. When the user clicks the edit button I handle the ListViews OnItemEditing event.

    In the EditItem template I have a txtbx(s) for the text values and a cmbo box for a list of choices for one of the data items. The combo box binds and displays choices just fine.

    So I thought it would be nice to find in the combobox the current (i.e. ListView item that has been clicked to edit) matching option, display it (find in combo box list of choices and make it selected choice) and this is where I hit my snag. I can't seem to get a handle on the DataItem....well actually I can and it is null???

    My reading while trying to solve reveals that the list is technically not yet in "edit" mode. If that is the case then does that mean the data item is not yet populated? This would explain why my data item is empty but then I can't find any other event to handle to achieve my objective?

    <telerik:RadListView ...<snip>... OnItemEditing="ExPrgmLstVw_ItemEditing" >
    ....Layout Template, ItemTemplate, EditTemplate, Insert Template......
    protected void ExPrgmLstVw_ItemEditing(object sender, RadListViewCommandEventArgs e)
      RadListViewDataItem itm = (RadListViewDataItem) e.ListViewItem;

    Here is the SO question as well so get yourself some SO points too! I have a screenshot here with the debugger showing my empty data item.

    So in summary I just need to know how to id the item being clicked for editing etc. so I can get at the data values for that item. Thank You
  2. Angel Petrov
    Angel Petrov avatar
    1002 posts

    Posted 12 Jun 2013 Link to this post

    Hello John,

    For obtaining a reference to the controls in the EditItemTemplate I suggest that you subscribe to the ItemDataBound event of the RadListView. By following this approach you should be able to manipulate the data and controls in the edit item. In the code snippet below is shown how you can reference a certain control by it's id:
    protected void RadListView1_ItemDataBound(object sender, RadListViewItemEventArgs e)
            if (e.Item is RadListViewEditableItem)
                RadListViewEditableItem item = e.Item as RadListViewEditableItem;
                TextBox textBox=item.FindControl("TextBox1") as TextBox;

    Angel Petrov
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. DevCraft R3 2016 release webinar banner
Back to Top