我具有的FormView的EditItemTemplate中的问题。

当我在InsertTemplate则一切正常使用这样的代码:

<asp:DropDownList ID="Lic_PosiadaczLicencjiIDDropDownList" runat="server" 
    SelectedValue='<%# Bind("Lic_PosiadaczLicencjiID") %>' />
<asp:CascadingDropDown ID="CascadingDropDown1" runat="server" 
    TargetControlID="Lic_PosiadaczLicencjiIDDropDownList" Category="Knt_Kod" 
    ServicePath="~/ManagerLicencjiService.asmx" ServiceMethod="GetKontrahenci">
</asp:CascadingDropDown>  

但是,当我在EditItemTemplate中使用完全相同的代码,我得到一个错误的SelectedValue是不元素列表上存在错误的原因。 我觉得现在的问题是,DropDownList会检查该值的之前它是由服务填充。当我运行调试器在服务方法断点前发生的误差。

如何解决这个问题?

有帮助吗?

解决方案

<rant>I've发现CCD非常笨重,全较差的记录workarounds</rant>的,但这里是你怎么做一些简单的填充DDL时选择的值。注意,所选择的值没有被设置在DDL并且它被传递给其中选择完成Web服务。

<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服务需要从你到上下文键添加到签名的你在哪里得到你的数据完全一样所示,因为它是区分大小写的。然后您检查返回值的选定值和选定的一组=真。如果你想选择的值,而不是选择文本,然后检查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;
}

希望这有助于!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top