Solved

Editing a nested DataList in ASP.NET C#

Posted on 2004-09-02
1
1,374 Views
Last Modified: 2012-06-27
Hi,

I have a nested DataList:

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

      <ItemTemplate>
      <asp:DataList id=DataList3 runat="server" DataSource='<%# DataBinder.Eval(Container,"DataItem.RelationLink")%>' OnUpdateCommand="Data_Update" OnCancelCommand="Data_Cancel" OnEditCommand="Data_Edit">
            <HeaderTemplate>
            </HeaderTemplate>
                                <ItemTemplate>
                                                                              <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>&nbsp;</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>
                                                                              <EditItemTemplate>
                  <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>
                          </EditItemTemplate>
                                                                              </asp:DataList>                                                            </ItemTemplate>
</asp:datalist>

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.

Mike
      
0
Comment
Question by:hydev
1 Comment
 
LVL 18

Accepted Solution

by:
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();
                                        break;
                  }
              }
-----------------------------------------------------------------------------------------------------------------------------------------------------------

-tushar
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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