Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Creating parent-child dependent dropdownlists within an ultrawebgrid
posted

Hi,

I'm trying to create a parent-child relation between two dropdownlists in two ultragrid columns. The webgrid is bound to a list of objects.

For example: one dropdownlist that contrains carbrands and a second that will contain the cars that are made by the selected brand in the first list. The complication is that both these dropdownlists are bound to the dataobject. (Because the object can both be bound to a specific car type or just a brand type.)

First i tried to do this with valuelists, but it seems that a valuelist has no 'selectedindexchanged' event or something like that. Therefore i cant trigger the second valuelist to rebind to his datasource. Is this possible in any way?

Next i tried to use templatecolumns, like this: (removed some of the markup code for visibility)

<igtbl:TemplatedColumn blablabla
<CellTemplate>
<asp:DropDownList DataSourceID="odsCarBrands" SelectedValue='<%#DataBinder.Eval(Container.DataItem,"Car_Brand_Id")%>' DataTextField="Type" DataValueField="Car_Brand_Id" ID="ddlCarBrand" runat="server" AutoPostBack="true" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlCarBrand_SelectedIndexChanged" />                                
</igtbl:TemplatedColumn>
<igtbl:TemplatedColumn blablabla
<CellTemplate>
<asp:DropDownList SelectedValue='<%#DataBinder.Eval(Container.DataItem,"Car_Id")%>' DataSourceID="odsCars" DataTextField="Name" DataValueField="Car_Id" ID="ddlCar" runat="server" AppendDataBoundItems="true">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="odsCars" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCarsByBrand" TypeName="Car" >
<SelectParameters>
<asp:Parameter Name="BrandId" Type="Int32" DefaultValue="-1" />
</SelectParameters>
</asp:ObjectDataSource>
</CellTemplate>
</igtbl:TemplatedColumn>

In the codebehind i handle the selectedindexchanged event by changing the objectdatasource's parameter and databinding the second dropdownlist. This is not very handy but it works a little bit. The problem is: when im trying to update the item i get errors like these:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

I'm familiair with there errors because they happen in detailviews as well when you have databound controls in databound controls. Its pretty much impossible to fix this without losing the automatic databinding.

Has anyone tried to do something like this before? Is there some easy way for this i'm overlooking? I cant imagine its this hard with an ultrawebgrid..

I'm very interested in any ideas about this..

Tim

Parents Reply Children