Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Problem with DataList within DataList

Reply
Thread Tools

Problem with DataList within DataList

 
 
Will
Guest
Posts: n/a
 
      10-10-2007
Hi Guys -

I am having a problem with one my datalist dlProjectCustomFields that
is 2 layers deep from my primary dlAccounts datalist. All my
datalists populate with the correct values withou any issues except
for the dlProjectCustomFields. All the data within the
dlProjectCustomFields is identical for each new item that is created
in my dlProjects datalist and I am not sure why. I have an
OnItemCreated function that kicks off and has a unique SONumber
associated with each one, and my DataLists when I assign them to the
dlProjectCustomFields are unique, however somewhere along the line all
the values are becoming identical. I have included my asp code, as
well as my dlProjects_OnItemCreated function below. Any assistance is
greatly appreciated as I am stumped. Thanks... Will

protected void dlProjects_OnItemCreated(Object sender,
DataListItemEventArgs e)
{
SqlDataSource sdsCustomValue = new
SqlDataSource(strConnection, "sc_GetCustomFieldValues");
sdsCustomValue.SelectCommandType =
SqlDataSourceCommandType.StoredProcedure;
Parameter pm = new Parameter("AccNumber", TypeCode.Int32,
((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString());
pm.Direction = ParameterDirection.Input;
sdsCustomValue.SelectParameters.Add(pm);
sdsCustomValue.DataSourceMode = SqlDataSourceMode.DataSet;
DataView dvSOCustomValues =
(DataView)sdsCustomValue.Select(DataSourceSelectAr guments.Empty);

DataView dvCurr = new DataView(dvProjectCustomFields.Table);
if (dvSOCustomValues.Count > 0)
{
foreach (DataRowView drv2 in dvSOCustomValues)
{
dvCurr.Table.Rows.Find(drv2.Row["CustomFieldDefinitionKeyID"])[3] =
drv2.Row["CustomFieldValue"];
}
}
DataList dl =
(DataList)e.Item.FindControl("dlProjectCustomField s");
dl.DataSource = new DataView(dvCurr.Table);
dl.DataBind();
}

<aspataList ID="dLAccounts" GridLines="both"
OnItemCreated="dlAccounts_OnItemCreated" runat="server">
<ItemTemplate>
<%# Eval("AccountName") %>
<%# Eval("AccountNumber") %>
<aspataList ID="AccCustomFields" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,
"CustomFieldLabel")%>
<%#DataBinder.Eval(Container.DataItem,"CustomField Value")
%>
</ItemTemplate>
</aspataList>
<aspataList ID="dlProjects" runat="server"
DataKeyField="SONumber" OnItemCreated="dlProjects_OnItemCreated">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"SONumber") %></td>
<%# DataBinder.Eval(Container.DataItem,"BriefDescripti on")
%>
<aspataList RepeatColumns="2"
ID="dlProjectCustomFields" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,
"CustomFieldLabel")%>
<%#DataBinder.Eval(Container.DataItem,"CustomField Value")
</ItemTemplate>
</aspataList>
</ItemTemplate>
</aspataList>
</ItemTemplate>
</aspataList>
 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      10-11-2007
Hi Will,

I'm having trouble to reproduce the issue from your posted code. I think a
complete reproducible project will be better to troubleshoot such issues.
Would you please send me one? Thank you for your effort.


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
Will
Guest
Posts: n/a
 
      10-14-2007
Hi Walter -

I have attached the cs and aspx file to this post. Please note that I
use a database to get the data, however I can't add this due to
security issues.

Wil

On Thu, 11 Oct 2007 07:54:43 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed) ("Walter
Wang [MSFT]") wrote:

>Hi Will,
>
>I'm having trouble to reproduce the issue from your posted code. I think a
>complete reproducible project will be better to troubleshoot such issues.
>Would you please send me one? Thank you for your effort.
>
>
>Regards,
>Walter Wang ((E-Mail Removed), remove 'online.')
>Microsoft Online Community Support
>
>================================================= =
>When responding to posts, please "Reply to Group" via your newsreader so
>that others may learn and benefit from your issue.
>================================================= =
>
>This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      10-15-2007
Hi Will,

Thanks for the code, it helped me to see more clearly about your objective,
although I cannot debug it since I don't have your database.

protected void dlProjects_OnItemCreated(Object sender,
DataListItemEventArgs e)
{
SqlDataSource sdsCustomValue = new SqlDataSource(strConnection,
"sc_GetCustomFieldValues");
sdsCustomValue.SelectCommandType =
SqlDataSourceCommandType.StoredProcedure;
Parameter pm = new Parameter("AccNumber", TypeCode.Int32,
((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString());
pm.Direction = ParameterDirection.Input;
sdsCustomValue.SelectParameters.Add(pm);
sdsCustomValue.DataSourceMode = SqlDataSourceMode.DataSet;
DataView dvSOCustomValues =
(DataView)sdsCustomValue.Select(DataSourceSelectAr guments.Empty);

DataView dvCurr = new DataView(dvProjectCustomFields.Table);
if (dvSOCustomValues.Count > 0)
{
foreach (DataRowView drv2 in dvSOCustomValues)
{

dvCurr.Table.Rows.Find(drv2.Row["CustomFieldDefinitionKeyID"])[3] =
drv2.Row["CustomFieldValue"];
}
}
DataList dl = (DataList)e.Item.FindControl("dlProjectCustomField s");
dl.DataSource = new DataView(dvCurr.Table);
dl.DataBind();
}

From above code, I can see you're using the member variable
dvProjectCustomFields.Table to create a new DataView and from there you
modified the data inside it. Please note this approach is directly
modifying the shared copy of DataTable from multiple
dlProjects_OnItemCreated invocations. That's why you're seeing the same
data.

The correct way is to create a copy of the dvProjectCustomFields.Table:

DataView dvCurr = new DataView(dvProjectCustomFields.Table.Copy());


Please try this and let me know the result. Thanks.


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      10-18-2007
Hi Will,

I'm writing to check the status of this post. Please feel free to let me
know if there's anything else I can help. Thanks.


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with creating Thumbnail Image within the Datalist? savvy ASP .Net 1 06-07-2006 11:29 AM
ASP 2.0 Problem with Nesting User Control containing a GridView within a DataList s.gregory@4castweb.com ASP .Net 0 12-06-2005 05:19 PM
Problem doing DataBind on a control within a DataList? Olav Tollefsen ASP .Net 2 12-29-2004 02:10 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Problem finding child control within nested DataList! Doug ASP .Net 1 04-22-2004 05:16 AM



Advertisments