473,221 Members | 2,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

DataList in DataList, how to do it???

I have DataList as part of DataList item. DataList in DataList. The parent
DataList working well including Edit command, that shows Edit template and
correctly bind the data into edit template (where is the child DataList)....

But in case I want to make Edit in this child DataList it is not working...
No edit template showed... :(

this is a code that i use for the child DataList... Edit command

// this is for child DataList...
protected void dlColumnMappings_EditCommand(object source,
DataListCommandEventArgs e)
{
DataList dlColumnMappings = (DataList)source;
dlColumnMappings.EditItemIndex = e.Item.ItemIndex;
dlColumnMappings.DataBind();
}
// this is for parent DataList.. it is working

protected void dlTransfers_EditCommand(object source,
DataListCommandEventArgs e)
{
dlTransfers.EditItemIndex = e.Item.ItemIndex;
dlTransfers.DataBind();
}
Mar 3 '06 #1
3 10250
Hi Mirek,

Welcome to the MSDN newsgroup.

As for the DataList databinding problem you mentioned, are you using
ASP.NET 2.0 and bind those DataList contro with some DataSource controls?
For ASP.NET 1.1, we need to reattache the DataSource when we redo the
databinding on DataList. For ASP.NET 2.0, I've just performed some simple
tests on myside and the edit command can work correct for both the parent
and nested sub DataList, therefore I think there may exists something else
incorrect which cause the problem behavior. Have you checked the template
to see whether all the button(for edit ) is assigned the "CommandName" as
Edit. Here is a test page's aspx template and the related event handler in
code behind, you can have a look for reference if can help:

===========aspx============
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=localhost;Initial
Catalog=Northwind;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT
[CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="Data Source=localhost;Initial
Catalog=Northwind;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP
3 [ProductID], [CategoryID], [ProductName] FROM [Products]">
</asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource1" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
CategoryID:
<asp:Label ID="CategoryIDLabel" runat="server" Text='<%#
Eval("CategoryID") %>'></asp:Label><br />
CategoryName:
<asp:Label ID="CategoryNameLabel" runat="server" Text='<%#
Eval("CategoryName") %>'></asp:Label><br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%#
Eval("Description") %>'></asp:Label><br />
<asp:Button ID="btnEdit" runat="server" CommandName="Edit"
Text="Edit" /><br />

</ItemTemplate>
<EditItemTemplate>
<asp:DataList ID="DataList2" runat="server"
DataSourceID="SqlDataSource2" OnItemCommand="DataList2_ItemCommand">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("ProductID") %>'></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("ProductName") %>'></asp:Label><br />
<asp:Label ID="Label3" runat="server" Text='<%#
Bind("CategoryID") %>'></asp:Label>
<asp:Button ID="btnEdit" runat="server"
CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("ProductID") %>'></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Text='<%#
Bind("ProductName") %>'></asp:TextBox>
<asp:Button ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
<asp:TextBox ID="TextBox3" runat="server" Text='<%#
Bind("CategoryID") %>'></asp:TextBox>
</EditItemTemplate>
</asp:DataList>
<asp:Button ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:DataList></div>

========code events=========

protected void DataList1_ItemCommand(object source,
DataListCommandEventArgs e)
{
switch (e.CommandName)
{
case "Edit":

DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();

break;

case "Cancel":

DataList1.EditItemIndex = -1;
DataList1.DataBind();

break;
}
}
protected void DataList2_ItemCommand(object source,
DataListCommandEventArgs e)
{
DataList dl = source as DataList;
switch (e.CommandName)
{
case "Edit":

dl.EditItemIndex = e.Item.ItemIndex;
dl.DataBind();

break;

case "Cancel":

dl.EditItemIndex = -1;
dl.DataBind();

break;
}
}
Hope these help.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Mar 6 '06 #2
Hi Steven,

The Transfers is List<Transfer>... Transfer object contain
List<DataColumnMapping>

This bound data into my child DataList , but the Edit command shows empty
template...
DataSource='<%# DataBinder.Eval(Container.DataItem, "DataColumnsMapping")
%>'
here is my code:
<asp:DataList ID="dlTransfers" runat="server" DataSource=<%# Transfers %>
OnItemCommand="dlTransfers_ItemCommand"
OnEditCommand="dlTransfers_EditCommand">
<ItemTemplate>
<asp:LinkButton ID="lbCaption" runat="server" CommandName="Edit"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>' Text='<%#
DataBinder.Eval(Container.DataItem, "Name") %>'></asp:LinkButton></td>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Width="593px" Text='<%#
DataBinder.Eval(Container.DataItem, "Name") %>'></asp:TextBox>
<asp:DataList ID="dlColumnMappings" runat="server" DataSource='<%#
DataBinder.Eval(Container.DataItem, "DataColumnsMapping") %>'
OnEditCommand="dlColumnMappings_EditCommand">
<ItemTemplate>
<table>
<tr>
<td id="tdSourceColumnName" runat="server" align="left" nowrap="nowrap"
valign="top" style="height: 12px">
<%# DataBinder.Eval(Container.DataItem, "SourceColumnName") %>
</td>
<td id="tdDestinationColumnName" runat="server" align="left" nowrap="nowrap"
valign="top" style="height: 12px">
<%# DataBinder.Eval(Container.DataItem, "DestinationColumnName") %>
</td>
<td>
<asp:LinkButton ID="lbEdit" runat="server"
CommandName="Edit">Edit</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtSourceColumnName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "SourceColumnName") %>'></asp:TextBox>
<asp:TextBox ID="txtDestinationClumnName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "DestinationColumnName")
%>'></asp:TextBox>
</EditItemTemplate>
</asp:DataList>
</EditItemTemplate>
</asp:DataList>


"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:8B*************@TK2MSFTNGXA03.phx.gbl...
Hi Mirek,

Welcome to the MSDN newsgroup.

As for the DataList databinding problem you mentioned, are you using
ASP.NET 2.0 and bind those DataList contro with some DataSource controls?
For ASP.NET 1.1, we need to reattache the DataSource when we redo the
databinding on DataList. For ASP.NET 2.0, I've just performed some simple
tests on myside and the edit command can work correct for both the parent
and nested sub DataList, therefore I think there may exists something else
incorrect which cause the problem behavior. Have you checked the template
to see whether all the button(for edit ) is assigned the "CommandName" as
Edit. Here is a test page's aspx template and the related event handler
in
code behind, you can have a look for reference if can help:

===========aspx============
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=localhost;Initial
Catalog=Northwind;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT
[CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="Data Source=localhost;Initial
Catalog=Northwind;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP
3 [ProductID], [CategoryID], [ProductName] FROM [Products]">
</asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource1" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
CategoryID:
<asp:Label ID="CategoryIDLabel" runat="server" Text='<%#
Eval("CategoryID") %>'></asp:Label><br />
CategoryName:
<asp:Label ID="CategoryNameLabel" runat="server" Text='<%#
Eval("CategoryName") %>'></asp:Label><br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%#
Eval("Description") %>'></asp:Label><br />
<asp:Button ID="btnEdit" runat="server" CommandName="Edit"
Text="Edit" /><br />

</ItemTemplate>
<EditItemTemplate>
<asp:DataList ID="DataList2" runat="server"
DataSourceID="SqlDataSource2" OnItemCommand="DataList2_ItemCommand">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("ProductID") %>'></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("ProductName") %>'></asp:Label><br />
<asp:Label ID="Label3" runat="server" Text='<%#
Bind("CategoryID") %>'></asp:Label>
<asp:Button ID="btnEdit" runat="server"
CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("ProductID") %>'></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Text='<%#
Bind("ProductName") %>'></asp:TextBox>
<asp:Button ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
<asp:TextBox ID="TextBox3" runat="server" Text='<%#
Bind("CategoryID") %>'></asp:TextBox>
</EditItemTemplate>
</asp:DataList>
<asp:Button ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:DataList></div>

========code events=========

protected void DataList1_ItemCommand(object source,
DataListCommandEventArgs e)
{
switch (e.CommandName)
{
case "Edit":

DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();

break;

case "Cancel":

DataList1.EditItemIndex = -1;
DataList1.DataBind();

break;
}
}
protected void DataList2_ItemCommand(object source,
DataListCommandEventArgs e)
{
DataList dl = source as DataList;
switch (e.CommandName)
{
case "Edit":

dl.EditItemIndex = e.Item.ItemIndex;
dl.DataBind();

break;

case "Cancel":

dl.EditItemIndex = -1;
dl.DataBind();

break;
}
}
Hope these help.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 6 '06 #3
Oh.. the problem is another...

The Transfers is List<Transfer>... single Transfer object contain
object DataMappings that is List<DataColumnMapping>.

DataList dlTransfers contains items, that contain DataList dlColumnMappings

The problem is in this hiearchical Binding i think...

dlTransfers.DataSource = Transfers
dlColumnMappings.DataSource = DataBinder.Eval(Container.DataItem,
"ColumnMappings");
protected void dlTransfers_EditCommand(object source,
DataListCommandEventArgs e)
{
dlTransfers.EditItemIndex = e.Item.ItemIndex;
dlTransfers.DataBind();
}

protected void dlColumnMappings_EditCommand(object source,
DataListCommandEventArgs e)
{
DataList dlColumnMappings = (DataList)source as DataList;
dlColumnMappings.EditItemIndex = e.Item.ItemIndex;

// in case I use this it shows me empty dlColumnMappings, because of
the dlTransfer was not Binded
// dlColumnMappings.DataBind();

// in case I use this it shows me binded dlColumnMappings, but not in
EditTemplate
// dlTransfers.DataBind();

}
Dont you know, how to use this hierarchical binding???

Thanks, Mirek.

"Mirek Endys" <Mi****@community.nospam> wrote in message
news:Ob**************@TK2MSFTNGP15.phx.gbl...
Hi Steven,

The Transfers is List<Transfer>... Transfer object contain
List<DataColumnMapping>

This bound data into my child DataList , but the Edit command shows empty
template...
DataSource='<%# DataBinder.Eval(Container.DataItem, "DataColumnsMapping")
%>'
here is my code:
<asp:DataList ID="dlTransfers" runat="server" DataSource=<%# Transfers %>
OnItemCommand="dlTransfers_ItemCommand"
OnEditCommand="dlTransfers_EditCommand">
<ItemTemplate>
<asp:LinkButton ID="lbCaption" runat="server" CommandName="Edit"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>'
Text='<%# DataBinder.Eval(Container.DataItem, "Name")
%>'></asp:LinkButton></td>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Width="593px" Text='<%#
DataBinder.Eval(Container.DataItem, "Name") %>'></asp:TextBox>
<asp:DataList ID="dlColumnMappings" runat="server" DataSource='<%#
DataBinder.Eval(Container.DataItem, "DataColumnsMapping") %>'
OnEditCommand="dlColumnMappings_EditCommand">
<ItemTemplate>
<table>
<tr>
<td id="tdSourceColumnName" runat="server" align="left" nowrap="nowrap"
valign="top" style="height: 12px">
<%# DataBinder.Eval(Container.DataItem, "SourceColumnName") %>
</td>
<td id="tdDestinationColumnName" runat="server" align="left"
nowrap="nowrap" valign="top" style="height: 12px">
<%# DataBinder.Eval(Container.DataItem, "DestinationColumnName") %>
</td>
<td>
<asp:LinkButton ID="lbEdit" runat="server"
CommandName="Edit">Edit</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtSourceColumnName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "SourceColumnName") %>'></asp:TextBox>
<asp:TextBox ID="txtDestinationClumnName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "DestinationColumnName")
%>'></asp:TextBox>
</EditItemTemplate>
</asp:DataList>
</EditItemTemplate>
</asp:DataList>


"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:8B*************@TK2MSFTNGXA03.phx.gbl...
Hi Mirek,

Welcome to the MSDN newsgroup.

As for the DataList databinding problem you mentioned, are you using
ASP.NET 2.0 and bind those DataList contro with some DataSource controls?
For ASP.NET 1.1, we need to reattache the DataSource when we redo the
databinding on DataList. For ASP.NET 2.0, I've just performed some simple
tests on myside and the edit command can work correct for both the parent
and nested sub DataList, therefore I think there may exists something
else
incorrect which cause the problem behavior. Have you checked the template
to see whether all the button(for edit ) is assigned the "CommandName" as
Edit. Here is a test page's aspx template and the related event handler
in
code behind, you can have a look for reference if can help:

===========aspx============
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=localhost;Initial
Catalog=Northwind;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT
[CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="Data Source=localhost;Initial
Catalog=Northwind;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP
3 [ProductID], [CategoryID], [ProductName] FROM [Products]">
</asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource1" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
CategoryID:
<asp:Label ID="CategoryIDLabel" runat="server" Text='<%#
Eval("CategoryID") %>'></asp:Label><br />
CategoryName:
<asp:Label ID="CategoryNameLabel" runat="server" Text='<%#
Eval("CategoryName") %>'></asp:Label><br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%#
Eval("Description") %>'></asp:Label><br />
<asp:Button ID="btnEdit" runat="server" CommandName="Edit"
Text="Edit" /><br />

</ItemTemplate>
<EditItemTemplate>
<asp:DataList ID="DataList2" runat="server"
DataSourceID="SqlDataSource2" OnItemCommand="DataList2_ItemCommand">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("ProductID") %>'></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("ProductName") %>'></asp:Label><br />
<asp:Label ID="Label3" runat="server" Text='<%#
Bind("CategoryID") %>'></asp:Label>
<asp:Button ID="btnEdit" runat="server"
CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%#
Bind("ProductID") %>'></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%#
Bind("ProductName") %>'></asp:TextBox>
<asp:Button ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
<asp:TextBox ID="TextBox3" runat="server"
Text='<%#
Bind("CategoryID") %>'></asp:TextBox>
</EditItemTemplate>
</asp:DataList>
<asp:Button ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:DataList></div>

========code events=========

protected void DataList1_ItemCommand(object source,
DataListCommandEventArgs e)
{
switch (e.CommandName)
{
case "Edit":

DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();

break;

case "Cancel":

DataList1.EditItemIndex = -1;
DataList1.DataBind();

break;
}
}
protected void DataList2_ItemCommand(object source,
DataListCommandEventArgs e)
{
DataList dl = source as DataList;
switch (e.CommandName)
{
case "Edit":

dl.EditItemIndex = e.Item.ItemIndex;
dl.DataBind();

break;

case "Cancel":

dl.EditItemIndex = -1;
dl.DataBind();

break;
}
}
Hope these help.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Mar 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: pete K | last post by:
Is it possible in asp.net to have a datalist in the itemtemplate of another datalist? For example: <asp:datalist id="MyList" runat="server"> <ItemTemplate> <table border="0" width="300">...
4
by: V. Jenks | last post by:
What seems like a simple thing is apparently not so straightforward? I have a datalist. Inside of that datalist is an <itemtemplate> secion which contains other server controls such as a...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
0
by: Les Caudle | last post by:
I have a menu system composed of a DataList nested inside a DataList. The outer DataList has it's DataSource (composed of a DataSet with two tables linked by a CategoryPagesRelation Relation) set...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.