Question

I was able to create a beautiful, four generation nested datalist (Parent, Child, GrandChild, GreatGrandChild) using a DataSet populated at Page_Load from a sub called Data_Binder(). I'm very pleased with how quickly and correctly the data displays.

However, when I click on the Edit button in my GreatGrandChild DataList, the info which should show in the EditItemTemplate completely disappears rather than allowing me to edit. This is what it looks like at the initial display:

Jul 2013
Stat Forecast Sales Brand
100           116   Drop 80 % 
Testing Insert
Part Number Mix DP Adj SP
8521150 30% 8    8 Edit
8521148 20% 5    5 Edit
8523458 10% 3    3 Edit
8524400 7%  2    2 Edit
8524276 6%  2    2 Edit
8523165 6%  2    2 Edit
8523985 5%  1  2 3 Edit
8523456 5%  1    1 Edit
8524403 4%  1    1 Edit
8524399 4%  1    1 Edit
8523987 3%  1    1 Edit
8524402 1%  0    0 Edit

Clicking Edit makes it become this:

Jul 2013
Stat Forecast Sales Brand
100           116   Drop 80 % 
Testing Insert

I'm including my GetChildRelation, Data_Binder, and Edit_Command subs so you can see what is triggering as well as my GreatGrandChild DataList. For brevity, I'm not including the HeaderTemplate and ItemTemplate as those are working just fine.

I would like to continue to use this DataSet method as the speed of presenting the data is fantastic.

Any suggestions?

Thanks,
Rob

Nested DataList snippet...

<asp:DataList ID="DL_Supply_Plan_Date_Numbers_SP" runat="server" 
    CssClass="DP_DL_Supply_Plan_Date_Numbers_SP" 
    OnEditCommand="Edit_Command"
    OnUpdateCommand="Update_Command"
    OnCancelCommand="Cancel_Command"
    DataSource='<%# GetChildRelation(Container.DataItem, "Fam_Date_GrandChild")%>'
    >
    <HeaderTemplate> ... </HeaderTemplate>
    <ItemTemplate> ... </ItemTemplate>
    <EditItemTemplate>

        <asp:Label ID="lbl_dat_DP_Date_Numbers_hidden" runat="server" CssClass="hidden" 
            Text='<%#Container.DataItem("dat_DP_Date")%>' />
        <asp:Label ID="lbl_txt_Part_Num_hidden" runat="server" CssClass="hidden" 
            Text='<%#Container.DataItem("txt_Part_Num")%>' />

        <asp:Label ID="lbl_txt_Family_Part_Num" runat="server" CssClass="SP_Family_Member"
            Text='<%#DataBinder.Eval(Container.DataItem,"txt_Family_Part_Num")%>' />
        <asp:Label ID="lbl_num_Mix_Weight" runat="server" CssClass="SP_Family_Member SP_Mix"
            Text='<%#DataBinder.Eval(Container.DataItem,"num_Mix_Weight","{0:0%}")%>' />
        <asp:Label ID="lbl_DP_Unconstrained" runat="server" CssClass="SP_Family_Member SP_Mix DP"
            Text='<%# Display_Supply_Plan(Eval("num_Mix_Weight"),Eval("num_DP_Number"),Eval("num_Brand_Number"),0) %>' />
        <asp:TextBox ID="tbx_num_SP_Adjust" runat="server" CssClass="SP_Family_Member SP_Mix SP-Adjust"
            Text='<%#DataBinder.Eval(Container.DataItem,"num_SP_Adjust")%>' />
        <asp:Label ID="lbl_SP" runat="server" CssClass="SP_Family_Member SP_Mix SP"
            Text='<%# Display_Supply_Plan(Eval("num_Mix_Weight"),Eval("num_DP_Number"),Eval("num_Brand_Number"),Eval("num_SP_Adjust")) %>' />
        <br />
        <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="update">Update</asp:LinkButton>
        &nbsp;&nbsp;
        <asp:LinkButton ID="lnkCancel" runat="server" CommandName="cancel">Cancel</asp:LinkButton>

    </EditItemTemplate>
</asp:DataList>

CODE BEHIND...

Protected Function GetChildRelation(dataItem As Object, relation As String) As DataView
    Dim drv As DataRowView = TryCast(dataItem, DataRowView)
    If drv IsNot Nothing Then
        Return drv.CreateChildView(relation)
    Else
        Return Nothing
    End If
End Function

Sub Data_Binder()

    Dim strConn As String = System.Configuration.ConfigurationManager.ConnectionStrings("TestConnectionString").ConnectionString

    Dim Cat_Fam_Filter As String = "Where txt_Family_Category Like '" & ddl_Family_Category_Name.SelectedValue & "' " _
                                    & "and txt_Family_Name Like '" & ddl_Family_Name.SelectedValue & "'"

    Dim strSql As String = "SELECT * FROM tbl_Family " & Cat_Fam_Filter & " Order By txt_Family_Category, txt_Family_Name ; " _
                           & "SELECT * FROM func_Display_Demand_Plan() " & Cat_Fam_Filter & " Order by dat_DP_Date; " _
                           & "SELECT * FROM func_Display_Demand_Plan() " & Cat_Fam_Filter & " Order by dat_DP_Date; " _
                           & "SELECT * FROM func_Display_Supply_Plan() " & Cat_Fam_Filter & " " _
                           & "order by dat_DP_Date, num_Mix_Weight DESC "

    Dim conn As New SqlConnection(strConn)
    Dim da As New SqlDataAdapter(strSql, conn)
    da.TableMappings.Add("Family1", "Dates")
    da.TableMappings.Add("Family2", "Demand")
    da.TableMappings.Add("Family3", "Supply")

    _ds = New DataSet()

    da.Fill(_ds, "Family")

    _ds.Relations.Add("Fam_Date_Parent", _ds.Tables("Family").Columns("txt_Family_Name"), _ds.Tables("Dates").Columns("txt_Family_Name"))
    _ds.Relations(0).Nested = True
    _ds.Relations.Add("Fam_Date_Child", _ds.Tables("Dates").Columns("FamDateKey"), _ds.Tables("Demand").Columns("FamDateKey"))
    _ds.Relations(1).Nested = True
    _ds.Relations.Add("Fam_Date_GrandChild", _ds.Tables("Demand").Columns("FamDateKey"), _ds.Tables("Supply").Columns("FamDateKey"), False)
    _ds.Relations(2).Nested = True

    DL_Supply_Plan.DataSource = _ds.Tables("Family")
    DL_Supply_Plan.DataBind()


End Sub

Sub Edit_Command(sender As Object, e As DataListCommandEventArgs)

    Dim DL_Target As DataList = DirectCast(sender, DataList)

    DL_Target.EditItemIndex = e.Item.ItemIndex
    DL_Target.DataBind()

End Sub
Was it helpful?

Solution

Since the GreatGrandChild was being populated via the DataSource using a Container.DataItem from the GrandChild datalist, any attempt to DataBind only the GreatGrandChild DataList would come up empty. I wasn't populating the entire DataView to get an appropriate DataRowView.

My solution: Create a DataSet for Parent, Child, and GrandChild and then a separate DataSet for GreatGrandChild. The GreatGrandChild is now populated via the GrandChild's OnItemDataBound event for display purposes. Then, I was able to use the same DataBind for the Edit, Cancel, and Update/Insert events as well. It is standalone and is working well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top