473,386 Members | 1,706 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,386 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 10264
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.