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!


Related Articles