开发者

Data Binding Error in cascading Drop downs in asp.net

I have 2 drop down list within the edit item Template of a form view. The first drop down contains a lit of vehicle Makes and the second a list of Vehicle Models. The list of models needs to be filtered by the selection from the Makes drop down.

Here are the 2 Drop down List

    <telerik:RadComboBox ID="RadComboBoxAssetMake" runat="server" DataTextField="AssetMakeName"
                                       SelectedValue='<%# Bind("MakeId") %>'         DataSourceID="odsAllAssetMakes" AutoPostBack="True" DataValueField="Id" Skin="Vista"
                                            Width="212px" OnSelectedIndexChanged="RadComboBoxAssetMake_SelectedIndexChanged">
                                            <telerik:Items>
                                                <telerik:RadComboBoxItem Text="" Value="" />
                                            </telerik:Items>

                                        </telerik:RadComboBox>
                                        <telerik:RadComboBox ID="RadComboBoxAssetModel" runat="server" DataTextField="AssetModelName"
                                     SelectedValue='<%# Bind("ModelId") %>'              DataSourceID="odsAssetModelByMake" DataValueField="Id" Skin="Vista" Width="212px">
                                            <telerik:Items>
                                                <telerik:RadComboBoxItem Text="" Value="" />
                                            </telerik:Items>
                                        </telerik:RadComboBox>

Initially I wanted to use a control select parameter on the object data source for the model Drop down. With the parameter getting the value from the Make drop down. However this doesn't seem to work as the select parameter on the object data source can't see the control with in the form view.

So now I am trying to use a session select parameter on the object data source.

 <asp:ObjectDataSource runat="server" ID="odsAssetModelByMake" DataObjectTypeName="GPSO.Repository.AssetModel"
    TypeName="GPSOnline.ATOMWebService" SelectMethod="GetAssetModelbyMake">
    <SelectParameters>                           
                  <asp:SessionParameter DbType="Guid" SessionField="assetMakeId" Name="assetMakeId"  />
    </SelectParameters>
</asp:ObjectDataSource>

But now I get the this error "Databinding met开发者_如何学Gohods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control." When I try to data bind the model drop down in the selected index changed method of the make drop down.

protected void RadComboBoxAssetMake_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Session["assetMakeId"] = e.Value.ToString();
        ((RadComboBox) fvAsset.FindControl("RadComboBoxAssetModel")).DataBind();           
    }

Is there a simple way to achieve this kind of thing, it would seem like such a common scenario that there must be a standard way to do it?


Initially I wanted to use a control select parameter on the object data source for the model Drop down. With the parameter getting the value from the Make drop down. However this doesn't seem to work as the select parameter on the object data source can't see the control with in the form view.


You need to move the ObjectDataSource into templates:

<EditItemTemplate>  
   <telerik:RadComboBox ....
   <telerik:RadComboBox ....
   <asp:ObjectDataSource ....
   <asp:ObjectDataSource ....
</EditItemTemplate>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜