Problem with DataList within DataList

Discussion in 'ASP .Net Web Controls' started by Will, Oct 10, 2007.

  1. Will

    Will Guest

    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(DataSourceSelectArguments.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("dlProjectCustomFields");
    dl.DataSource = new DataView(dvCurr.Table);
    dl.DataBind();
    }

    <asp:DataList ID="dLAccounts" GridLines="both"
    OnItemCreated="dlAccounts_OnItemCreated" runat="server">
    <ItemTemplate>
    <%# Eval("AccountName") %>
    <%# Eval("AccountNumber") %>
    <asp:DataList ID="AccCustomFields" runat="server">
    <ItemTemplate>
    <%#DataBinder.Eval(Container.DataItem,
    "CustomFieldLabel")%>
    <%#DataBinder.Eval(Container.DataItem,"CustomFieldValue")
    %>
    </ItemTemplate>
    </asp:DataList>
    <asp:DataList ID="dlProjects" runat="server"
    DataKeyField="SONumber" OnItemCreated="dlProjects_OnItemCreated">
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem,"SONumber") %></td>
    <%# DataBinder.Eval(Container.DataItem,"BriefDescription")
    %>
    <asp:DataList RepeatColumns="2"
    ID="dlProjectCustomFields" runat="server">
    <ItemTemplate>
    <%#DataBinder.Eval(Container.DataItem,
    "CustomFieldLabel")%>
    <%#DataBinder.Eval(Container.DataItem,"CustomFieldValue")
    </ItemTemplate>
    </asp:DataList>
    </ItemTemplate>
    </asp:DataList>
    </ItemTemplate>
    </asp:DataList>
    Will, Oct 10, 2007
    #1
    1. Advertising

  2. 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 (, 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.
    Walter Wang [MSFT], Oct 11, 2007
    #2
    1. Advertising

  3. Will

    Will Guest

    Re: Problem with DataList within DataList (0/1)

    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, ("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 (, 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.
    Will, Oct 14, 2007
    #3
  4. Re: Problem with DataList within DataList (0/1)

    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(DataSourceSelectArguments.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("dlProjectCustomFields");
    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 (, 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.
    Walter Wang [MSFT], Oct 15, 2007
    #4
  5. Re: Problem with DataList within DataList (0/1)

    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 (, 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.
    Walter Wang [MSFT], Oct 18, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug
    Replies:
    1
    Views:
    3,973
    Rick Spiewak
    Apr 22, 2004
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,848
  3. Olav Tollefsen
    Replies:
    2
    Views:
    1,881
    Olav Tollefsen
    Dec 29, 2004
  4. Replies:
    0
    Views:
    1,459
  5. savvy
    Replies:
    1
    Views:
    520
    savvy
    Jun 7, 2006
Loading...

Share This Page