我能够使用一个名为Data_Binder()的子页面中的Page_Load填充的DataSet创建一个漂亮的四代嵌套数据列表(Parent,Child,GrandChild,GreatGrandChild)。我对数据显示的快速和正确感到非常满意。
然而,当我点击GreatGrandChild DataList中的Edit按钮时,应该在EditItemTemplate中显示的信息完全消失,而不是允许我编辑。这是初始显示时的样子:
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
点击“编辑”使其成为:
Jul 2013
Stat Forecast Sales Brand
100 116 Drop 80 %
Testing Insert
我包含了我的GetChildRelation,Data_Binder和Edit_Command subs,因此您可以看到触发的内容以及我的GreatGrandChild DataList。为简洁起见,我不包括HeaderTemplate和ItemTemplate,因为它们工作正常。
我想继续使用这种DataSet方法,因为呈现数据的速度非常棒。
有什么建议吗?
谢谢,
罗布
嵌套的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>
<asp:LinkButton ID="lnkCancel" runat="server" CommandName="cancel">Cancel</asp:LinkButton>
</EditItemTemplate>
</asp:DataList>
代码背后......
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
答案 0 :(得分:0)
由于GreatGrandChild是使用来自GrandChild数据列表的Container.DataItem通过DataSource填充的,因此任何只有GreatGrandChild DataList的DataBind尝试都会显示为空。我没有填充整个DataView以获得适当的DataRowView。
我的解决方案:为Parent,Child和GrandChild创建一个DataSet,然后为GreatGrandChild创建一个单独的DataSet。 GreatGrandChild现在通过GrandChild的OnItemDataBound事件填充以用于显示目的。然后,我也可以使用相同的DataBind进行编辑,取消和更新/插入事件。它是独立的,运行良好。