У меня есть 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
для 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>
Кроме того, для полноты это 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
до ddlClienti
в режимах вставки и редактирования DetailsView1
?
Ниже приведен снимок экрана представления сведений:
Заранее спасибо.