ListView 内的 DropDownList
DropDownList inside ListView
我在 ListView 中有一个 DropDownList。 ListView 显示公司的员工,DDL 列出他们可以分配到的组。
我使用了 2 个独立的数据源。一种用于列出员工,另一种用于列出组。看起来不错,但每当我尝试更新组时,它都没有注册。
如何确保 DDL 是员工更新查询的一部分,即使它已连接到另一个数据源?
我在这里找不到任何相关信息。珍惜你的时间,谢谢。 :)
数据源:
<asp:LinqDataSource
ID="LinqDataSource_Employees"
runat="server"
ContextTypeName="Blabla.bla.myContext"
EntityTypeName=""
OrderBy="Group_ID, DisplayName"
TableName="Employees"
EnableDelete="True"
EnableInsert="True"
EnableUpdate="True">
</asp:LinqDataSource>
<asp:LinqDataSource
ID="LinqDataSource_Groups"
runat="server"
ContextTypeName="Blabla.bla.myContext"
EntityTypeName=""
Select="new (ID, Name)"
TableName="Groups">
</asp:LinqDataSource>
编辑项目模板:
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="ID_UserNameLabel" runat="server" Text='<%# Eval("ID_UserName") %>' />
</td>
<td>
<asp:TextBox ID="DisplayNameTextBox" runat="server" Text='<%# Bind("DisplayName") %>' />
</td>
<td>
<asp:TextBox ID="EmailAddressTextBox" runat="server" Text='<%# Bind("EmailAddress") %>' />
</td>
<td>
<asp:TextBox ID="PhoneNumberTextBox" runat="server" Text='<%# Bind("PhoneNumber") %>' />
</td>
<td>
<asp:DropDownList ID="GroupDropDownList" runat="server" DataSourceID="LinqDataSource_Groups" DataTextField="Name" DataValueField="ID" />
</td>
</tr>
</EditItemTemplate>
再 digging 之后,我找到了如何继续的线索。
事实证明,如果您在 属性 SelectedValue 上使用 Bind,它将绑定到 ListView 的数据源,而不是声明式绑定的数据源在数据源 属性 中设置。 :)
<asp:DropDownList
ID="GroupDropDownList"
runat="server"
DataSourceID="LinqDataSource_Groups"
DataTextField="Name"
DataValueField="ID"
SelectedValue='<%# Bind("Group_ID") %>' />
希望这对某人有所帮助。 :)
我在 ListView 中有一个 DropDownList。 ListView 显示公司的员工,DDL 列出他们可以分配到的组。
我使用了 2 个独立的数据源。一种用于列出员工,另一种用于列出组。看起来不错,但每当我尝试更新组时,它都没有注册。
如何确保 DDL 是员工更新查询的一部分,即使它已连接到另一个数据源?
我在这里找不到任何相关信息。珍惜你的时间,谢谢。 :)
数据源:
<asp:LinqDataSource
ID="LinqDataSource_Employees"
runat="server"
ContextTypeName="Blabla.bla.myContext"
EntityTypeName=""
OrderBy="Group_ID, DisplayName"
TableName="Employees"
EnableDelete="True"
EnableInsert="True"
EnableUpdate="True">
</asp:LinqDataSource>
<asp:LinqDataSource
ID="LinqDataSource_Groups"
runat="server"
ContextTypeName="Blabla.bla.myContext"
EntityTypeName=""
Select="new (ID, Name)"
TableName="Groups">
</asp:LinqDataSource>
编辑项目模板:
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="ID_UserNameLabel" runat="server" Text='<%# Eval("ID_UserName") %>' />
</td>
<td>
<asp:TextBox ID="DisplayNameTextBox" runat="server" Text='<%# Bind("DisplayName") %>' />
</td>
<td>
<asp:TextBox ID="EmailAddressTextBox" runat="server" Text='<%# Bind("EmailAddress") %>' />
</td>
<td>
<asp:TextBox ID="PhoneNumberTextBox" runat="server" Text='<%# Bind("PhoneNumber") %>' />
</td>
<td>
<asp:DropDownList ID="GroupDropDownList" runat="server" DataSourceID="LinqDataSource_Groups" DataTextField="Name" DataValueField="ID" />
</td>
</tr>
</EditItemTemplate>
再 digging 之后,我找到了如何继续的线索。
事实证明,如果您在 属性 SelectedValue 上使用 Bind,它将绑定到 ListView 的数据源,而不是声明式绑定的数据源在数据源 属性 中设置。 :)
<asp:DropDownList
ID="GroupDropDownList"
runat="server"
DataSourceID="LinqDataSource_Groups"
DataTextField="Name"
DataValueField="ID"
SelectedValue='<%# Bind("Group_ID") %>' />
希望这对某人有所帮助。 :)