<rant>
我发现CCD非常笨重,而且到处都是文档不全的解决方法
</rant>
<asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
<asp:FormView ID="fv1" runat="server" DataSourceID="yourDataSource">
<EditItemTemplate>
<asp:DropDownList ID="Lic_PosiadaczLicencjiIDDropDownList" runat="server" />
<asp:CascadingDropDown ID="CascadingDropDown1" runat="server"
TargetControlID="Lic_PosiadaczLicencjiIDDropDownList" Category="Knt_Kod"
ServicePath="~/ManagerLicencjiService.asmx" ServiceMethod="GetKontrahenci"
UseContextKey="true" ContextKey='<%# Bind("Lic_PosiadaczLicencjiID") %>'>
</asp:CascadingDropDown>
</EditItemTemplate>
</asp:FormView>
<asp:sqldatasource id="yourDataSource"
selectcommand="select Lic_PosiadaczLicencjiID FROM yourdatabase"
UpdateCommand="Update yourdatabase set Lic_PosiadaczLicencjiID = @newvalue WHERE Lic_PosiadaczLicencjiID = @Lic_PosiadaczLicencjiID"
connectionstring="<%$ ConnectionStrings:yourConnectionString %>"
runat="server"
onupdating="yourDataSource_Updating">
<UpdateParameters>
<asp:Parameter Name="newvalue" DbType="String" />
</UpdateParameters>
</asp:sqldatasource>
代码隐藏:
protected void yourDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters["@newvalue"].Value = ((DropDownList)fv1.FindControl("Lic_PosiadaczLicencjiIDDropDownList")).SelectedValue;
}
在从中获取数据的web服务中,需要向签名添加上下文键
完全如图所示
因为它区分大小写。然后检查所选值的返回值并设置selected=true。如果要选择“值”而不是“选定文本”,请检查“x.value”而不是“x.name”。
[WebMethod]
public CascadingDropDownNameValue[] GetKontrahenci(string knownCategoryValues, string category, string contextKey)
{
CascadingDropDownNameValue[] results = getdata();
CascadingDropDownNameValue selectedVal = (from x in results where x.name == contextKey select x).FirstOrDefault();
if (selectedVal != null)
selectedVal.isDefaultValue = true;
return results;
}
希望这有帮助!