我有DetailsView
这样:
<asp:DetailsView ID="detailsView1" runat="server"
DataSourceID="edsdetailsView" AutoGenerateRows="False" CssClass="pretty-table">
<Fields>
<asp:TemplateField HeaderText="Cliente">
<ItemTemplate>
<asp:Label ID="dw1Label2" runat="server" Text='<%# Bind("Clienti.NomeSocieta") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlClienti" runat="server" SelectedValue='<%# Bind("IDCliente") %>'
Width="300" DataSourceID="EntityDataSourceClienti" DataTextField="NomeSocieta"
AutoPostBack="true" DataValueField='IDCliente'
onselectedindexchanged="ddlClienti_SelectedIndexChanged">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="ddlClienti" runat="server" SelectedValue='<%# Bind("IDCliente") %>'
Width="300" DataSourceID="EntityDataSourceClienti" DataTextField="NomeSocieta"
AutoPostBack="true" DataValueField='IDCliente'
onselectedindexchanged="ddlClienti_SelectedIndexChanged">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contatto" SortExpression="IDContatto">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Contatti.Nome") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlContatti" runat="server" SelectedValue='<%# Bind("IDContatto") %>'
Width="300px" DataSourceID="edsContatti" DataTextField="Nome"
DataValueField='IDContatto'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="ddlContatti" runat="server" SelectedValue='<%# Bind("IDContatto") %>'
Width="300" DataSourceID="edsContatti" DataTextField="Nome"
DataValueField='IDContatto'/>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
它有一个名为Cliente
的字段,连接到EntityDataSource
:
<asp:EntityDataSource ID="EntityDataSourceClienti" runat="server" ConnectionString="name=SalesPortalEntities"
DefaultContainerName="SalesPortalEntities" EnableFlattening="False" EntitySetName="Clienti"
OrderBy="it.NomeSocieta" EntityTypeFilter="Clienti">
</asp:EntityDataSource>
当我更改Contatto
字段的选择时,我想要更改另一个字段Cliente
。 EntityDataSource
的{{1}}是:
Contatto
此外,为了完整性,这是<asp:EntityDataSource ID="edsContatti" runat="server" ConnectionString="name=SalesPortalEntities"
DefaultContainerName="SalesPortalEntities" EnableFlattening="False" EntitySetName="Contatti"
Where="it.IDAzienda=@IDClienteFromDdl">
<WhereParameters>
<asp:Parameter Name="IDClienteFromDdl" Type="Int32"/>
</WhereParameters>
</asp:EntityDataSource>
的{{1}}:
EntityDataSource
代码隐藏是:
DetailsView1
如何在<asp:EntityDataSource ID="edsdetailsView" runat="server" Include="Categorie,Commerciali,Clienti,Contatti"
ConnectionString="name=SalesPortalEntities" OnInserting="UpdateDataSource" DefaultContainerName="SalesPortalEntities"
EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True"
EntitySetName="PianificazioneIncontri" Where="it.IDPianificazione = @IDPianificazione AND ((it.Obsoleto=false AND it.ApprovazioneModifica=false AND it.ApprovazioneEliminazione=false) OR (@GruppoAdmin='1' AND it.Obsoleto=false))"
OnUpdating="edsdetailsView_Updating">
<WhereParameters>
<asp:ControlParameter ControlID="GridView1" Name="IDPianificazione" PropertyName="SelectedValue" Type="Int32" />
<asp:Parameter Name="GruppoAdmin" Type="String" />
</WhereParameters>
</asp:EntityDataSource>
的插入和编辑模式中将protected void ddlClienti_SelectedIndexChanged(object sender, EventArgs e)
{
edsContatti.WhereParameters[0].DefaultValue = ((DropDownList)sender).SelectedValue;
}
挂钩到ddlContatti
?
以下是详细信息视图的屏幕截图:
提前致谢。
答案 0 :(得分:1)
再试一次,如果这不起作用,我会放弃浪费你的时间=)
protected void ddlClienti_SelectedIndexChanged(object sender, EventArgs e)
{
edsContatti.WhereParameters[0].DefaultValue = ((DropDownList)sender).SelectedValue;
// Call DataBind to reload the DataSource based on the new WHERE clause
edsContatti.DataBind();
// Since you're using a DetailsView, you have to find the nested control within it
DropDownList ddlContatti = (DropDownList)DetailsView1.FindControl("ddlConcatti");
// And then call DataBind on it as well
detailsView1.DataBind();
}