简体   繁体   English

编辑嵌套的DataList错误

[英]Edit Nested DataList error

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(). 我能够使用填充在Page_Load的DataSet中的一个名为Data_Binder()的数据集创建漂亮的四代嵌套数据列表(Parent,Child,GrandChild,GreatGrandChild)。 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. 但是,当我单击GreatGrandChild数据列表中的“编辑”按钮时,应显示在EditItemTemplate中的信息完全消失,而不是允许我进行编辑。 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. 我包括了GetChildRelation,Data_Binder和Edit_Command子程序,因此您可以看到正在触发的内容以及GreatGrandChild DataList。 For brevity, I'm not including the HeaderTemplate and ItemTemplate as those are working just fine. 为简便起见,我不包括HeaderTemplate和ItemTemplate,因为它们工作得很好。

I would like to continue to use this DataSet method as the speed of presenting the data is fantastic. 我想继续使用此DataSet方法,因为呈现数据的速度非常好。

Any suggestions? 有什么建议么?

Thanks, 谢谢,
Rob

Nested DataList snippet... 嵌套的DataList代码段...

<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

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. 由于使用GrandChild数据列表中的Container.DataItem通过DataSource填充了GreatGrandChild,因此仅尝试将BigGrandChild DataList绑定到DataBind的任何尝试都将为空。 I wasn't populating the entire DataView to get an appropriate DataRowView. 我没有填充整个DataView来获取合适的DataRowView。

My solution: Create a DataSet for Parent, Child, and GrandChild and then a separate DataSet for GreatGrandChild. 我的解决方案:为Parent,Child和GrandChild创建一个数据集,然后为GreatGrandChild创建一个单独的数据集。 The GreatGrandChild is now populated via the GrandChild's OnItemDataBound event for display purposes. 现在,为了显示目的,通过GrandChild的OnItemDataBound事件填充了GreatGrandChild。 Then, I was able to use the same DataBind for the Edit, Cancel, and Update/Insert events as well. 然后,我也可以对Edit,Cancel和Update / Insert事件使用相同的DataBind。 It is standalone and is working well. 它是独立的,并且运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM