Editing a nested DataList in ASP.NET C#

Posted on 2004-09-02
Last Modified: 2012-06-27

I have a nested DataList:

<asp:datalist id="DataList1" runat="server" Width="450">
       (removed to save space)

      <asp:DataList id=DataList3 runat="server" DataSource='<%# DataBinder.Eval(Container,"DataItem.RelationLink")%>' OnUpdateCommand="Data_Update" OnCancelCommand="Data_Cancel" OnEditCommand="Data_Edit">
                                                                              <td width="20">&nbsp;</td>
<td class="BODYTEXT10" align="right" width="50"><%# DataBinder.Eval(Container.DataItem,"Size")%></td>
<td class="BODYTEXT10" align="center" width="50"><%# DataBinder.Eval(Container.DataItem,"Qty")%></td>
<td class="BODYTEXT8ITALIC" align="center" width="30"><%# DataBinder.Eval(Container.DataItem,"Min")%></td>
<td class="BODYTEXT8ITALIC" align="center" width="30"><%# DataBinder.Eval(Container.DataItem,"Max")%></td>
<td class="BODYTEXT8ITALIC" align="center" width="50"><%# DataBinder.Eval(Container.DataItem,"OnOrder")%></td>
<td class="BODYTEXT8ITALIC" align="left" width="120"><%# DataBinder.Eval(Container.DataItem,"DueDate")%></td>
<TD><asp:Button id="ButEdit" runat="server" Text="Edit"></asp:Button></TD></ItemTemplate>
                  <asp:TextBox cssclass="BODYTEXT10" id="TextBoxEditQty" runat="server" columns=3 Text='<%# DataBinder.Eval(Container.DataItem,"Qty")%>'></asp:TextBox></td><td>&nbsp;</td>
<td class="BODYTEXT8ITALIC" width="30"><%# DataBinder.Eval(Container.DataItem,"Min")%></td>
<td class="BODYTEXT8ITALIC" width="30"><%# DataBinder.Eval(Container.DataItem,"Max")%></td>
<td class="BODYTEXT8ITALIC" width="50"><%# DataBinder.Eval(Container.DataItem,"OnOrder")%></td>
<td class="BODYTEXT8ITALIC" width="120"><%# DataBinder.Eval(Container.DataItem,"DueDate")%></td>
<td><asp:Button id="ButCancel" runat="server" Text="Cancel" cssclass="BODYTEXT10"></asp:Button></td>
<td><asp:Button id="ButUpdate" runat="server" Text="Update" cssclass="BODYTEXT10"></asp:Button></td>
                                                                              </asp:DataList>                                                            </ItemTemplate>

The problem is that when you click on the "Edit" button in the second datalist it does not go into Edit mode.  Im guessing the whole thing is reloading and resetting itself. Reading on the net I understand I only need to refresh the nested datalist but how?  

The top of the C# file says:

protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.Button ButEdit;
protected System.Web.UI.WebControls.TextBox TextBox1;

There is no reference for the nested datalist so the line DataList3.DataSource = xxx causes an error because it doens't exist.  If I add  the line protected System.Web.UI.WebControls.DataList DataList3;  It then fails becuase of duplicate naming.

Basically I am a bit confused on this one.  Can anyone help? - It would be be appreciated.

Question by:hydev
1 Comment
LVL 18

Accepted Solution

tusharashah earned 500 total points
ID: 11965724
As you are nesting datalist. You cannot directly referenct it like 'DataList3.DataSource'. For binding that DataList see below:>

private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        switch( e.Item.ItemType )
            case ListItemType.Item:
            case ListItemType.AlternatingItem:
                                                 ( (DataList) e.FindControl("DataList3") ).DataSource = xxx;
                                                 ( (DataList) e.FindControl("DataList3") ).DataBind();


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question