Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>hope that will serve someone, somewhere.</p> <p>Here is my code to get that to work:</p> <p>1) I have a Listview wich hold a user control when editing. This User cotnrol has itself a listview inside</p> <pre><code>&lt;asp:ListView runat=server ID=C_LV_MyObjects DataKeyNames="Id" OnItemDataBound=DataBoundMyObjects OnItemEditing=ItemEditing &gt; &lt;LayoutTemplate&gt; &lt;table runat=server id="itemPlaceholderContainer"&gt; &lt;tr&gt; &lt;th&gt; Description &lt;/th&gt; &lt;/tr&gt; &lt;tr runat="server" id="itemPlaceholder"&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt; text... &lt;/td&gt; &lt;td&gt; &lt;asp:LinkButton runat="server" CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:LinkButton runat="server" CommandName="Delete" Text="Delete"&gt;&lt;/asp:LinkButton&gt; &lt;/td&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;tr&gt; &lt;td colspan=3&gt; &lt;MyTag:MyUC ID=C_UC_MyUserControl runat=server OnEditing=MyObjectEditing /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/EditItemTemplate&gt; &lt;EmptyDataTemplate&gt; No results found! &lt;/EmptyDataTemplate&gt; &lt;/asp:ListView&gt; </code></pre> <p>The code c# for this listview is as follows :</p> <pre><code>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(); } } </code></pre> <p>and the code of my Usercontrol is as follows :</p> <pre><code>&lt;asp:PlaceHolder runat="server" ID="C_PH_ObjComposition"&gt; &lt;asp:ListView runat="server" ID="C_LV_AppaltatoreComposizione" DataSource="&lt;% # DataSource %&gt;" DataKeyNames="Id" OnItemEditing="ItemEditing"&gt; etc... &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:LinkButton runat="server" CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;tr&gt; &lt;td&gt; Edit Mode &lt;/td&gt; &lt;/tr&gt; &lt;/EditItemTemplate&gt; &lt;/asp:ListView&gt; &lt;/asp:PlaceHolder&gt; </code></pre> <p>with the following code c# :</p> <pre><code>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); } </code></pre> <p>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.</p> <p>That's all if you have any questions , please feel free to answer..</p> <p>ciao!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload