score:2
This is an interesting problem. Almost certainly a databinding issue. In order to enter edit mode you must do two things:
1) Set the EditIndex
2) Call DataBind()
In the case of nested repeaters though... when does Render get called? I suspect you will have to call DataBind() on the PARENT in order to render everything correctly. That being the case you may have to then set the EditIndex AGAIN, since you are rebinding the parent.
EDIT: OK... I just tried this with a nested GridView and I did NOT have to DataBind() the parent to get the sub grid to enter edit mode. Now I have to downvote my own answer. :|
score:0
hope that will serve someone, somewhere.
Here is my code to get that to work:
1) I have a Listview wich hold a user control when editing. This User cotnrol has itself a listview inside
<asp:ListView runat=server ID=C_LV_MyObjects DataKeyNames="Id"
OnItemDataBound=DataBoundMyObjects OnItemEditing=ItemEditing
>
<LayoutTemplate>
<table runat=server id="itemPlaceholderContainer">
<tr>
<th>
Description
</th>
</tr>
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
text...
</td>
<td>
<asp:LinkButton runat="server" CommandName="Edit" Text="Edit"></asp:LinkButton>
</td>
<td>
<asp:LinkButton runat="server" CommandName="Delete" Text="Delete"></asp:LinkButton>
</td>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td colspan=3>
<MyTag:MyUC ID=C_UC_MyUserControl runat=server
OnEditing=MyObjectEditing
/>
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
No results found!
</EmptyDataTemplate>
</asp:ListView>
The code c# for this listview is as follows :
public int EditIndexComposition;
protected void ItemEditing(object sender, ListViewEditEventArgs e)
{
C_LV_MyObjects.EditIndex = e.NewEditIndex;
C_LV_MyObjects.DataBind();
}
protected void MyObjectEditing(object sender, EventArgs e)
{
ListViewEditEventArgs MyEvent = (ListViewEditEventArgs)e;
if (MyEvent != null)
EditIndexComposition= MyEvent.NewEditIndex;
C_LV_MyObjects.DataBind();
}
protected void DataBoundMyObjects(object sender, ListViewItemEventArgs e)
{
MyUC uc = (MyUC)e.Item.FindControl("C_UC_MyUserControl");
if (uc!=null)
{
uc.EditIndex = EditIndexComposition;
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
MyObject obj= (MyObject)dataItem.DataItem;
uc.DataSource=Myservice.GetDatasource(obj.Id);
uc.DataBind();
}
}
and the code of my Usercontrol is as follows :
<asp:PlaceHolder runat="server" ID="C_PH_ObjComposition">
<asp:ListView runat="server" ID="C_LV_AppaltatoreComposizione" DataSource="<% # DataSource %>"
DataKeyNames="Id" OnItemEditing="ItemEditing">
etc...
<ItemTemplate>
<tr>
<td>
<asp:LinkButton runat="server" CommandName="Edit" Text="Edit"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td>
Edit Mode
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
</asp:PlaceHolder>
with the following code c# :
public int EditIndex
{
get {return C_LV_ObjComposition.EditIndex;}
set { C_LV_ObjComposition.EditIndex=value;}
}
public event EventHandler Editing;
protected void ItemEditing(object sender, ListViewEditEventArgs e)
{
C_LV_ObjComposition.EditIndex = e.NewEditIndex;
if (Editing != null)
Editing(this, e);
}
When clicking on the edit button of the innerlistview, we store the index that was clicked and we trigger a function in the first container user control. This function is going to store in a global value the index cliked and triggers a databind of the outter list. Doing so we get the onitemdatabound, that will recreate our usercontrol with the proper values, we can then before the databinding of the usercontrol assign the index of the editing row.
That's all if you have any questions , please feel free to answer..
ciao!
Source: stackoverflow.com
Related Articles
- How to Edit data in nested Listview
- ASP.Net LINQ data source error is ListView
- c# Linq or code to extract groups from a single list of source data
- The data source does not support server-side data paging
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource
- Calling fellow code nerds - Alternatives to Nested Loops?
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- How does linq actually execute the code to retrieve data from the data source?
- Pivot data in two nested List<T> with Linq
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- Is there a way to speed up this code that finds data changes in two XML files?
- The given value of type String from the data source cannot be converted to type int of the specified target column
- Merge duplicate data without affecting others in LINQ code
- LINQ Query to put data in a nested object
- Use a linq query as microsoft local report Data Source (WinForms)
- How to fill data in nested Lists based on Ids in C#?
- StackOverflowException using Linq(Kit) for nested data
- At what point is a LINQ data source determined?
- LINQ and group by data nested within a structure
- creating Linq to sqlite dbml from DbLinq source code
- Populate Nested List of Classes from single data table c#
- Use ListView control to display data but join a reference table
- read icollection data using LINQ in C# code
- Fastest method to Fill Data in Nested List
- updating data in many-to-many relationship in entity framework in code first existing database
- Linq group by to create nested listview
- Linq to sql as object data source - designer problem with partial classes
- Dynamic LINQ: Comparing Nested Data With Parent Property
- String.Format in linq query
- Nested expression building with linq and Entity Framework
- ADO.NET Entity Framework: Converting String to Int in Where/OrderBY
- LINQ: transform an array [,] into array[]
- In statement for LINQ to objects
- Querying Datatable DBNull using Linq Query
- LINQ or Lambda for two for loops
- Using LINQ2SQL Efficiently
- Specific node in XML
- Check for Null while Creating XML document from object list
- Linq OrderBy Sub List
- linq select sum and average into view model
- Regex alternative for extracting numeric and non-numeric strings
- Changing XML with Linq
- Using index in SelectMany LINQ
- Linq to SQL one to many relationships
- MySql ORDER BY FIELD() in EntityFramework
- Proper way to Categorize by a Property
- Issue when trying to determine common elements in two List<T>
- add item to property(list object type) in list object c#