Solved

Editing a nested DataList in ASP.NET C#

Posted on 2004-09-02
1
1,369 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now