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

Accessing ListView Item Being Edited

1 Answer 200 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Ramjet
Top achievements
Rank 1
Ramjet asked on 09 Jun 2013, 03:18 PM

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......
</telerik:RadListView>
 
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.
(http://stackoverflow.com/questions/16986363/accessing-listview-item-being-edited)


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
JB

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 12 Jun 2013, 04:36 PM
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;
        }
    }


Regards,
Angel Petrov
Telerik
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.
Tags
ListView
Asked by
Ramjet
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or