Solved

Editing a nested DataList in ASP.NET C#

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

15 Experts available now in Live!

Get 1:1 Help Now