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
  • 49378
    Suggested Answer
    posted

    Hi Tim,

    The best way to achieve the behavior you are looking for would be to use multiple WebCombo controls as editor providers for your respective columns. In this case you can handle the SelectedRowChanged in order to implement your logic.

    The WebCombo may be bound to a data source. In order to bind a WebCombo editor to a column, you need to:

    1. Add a new column to the grid
    2. Set the column's EditorControlD property to the id of the combo
    3. Set the column's Type to custom

    To answer your other question, it is possible to use ValueLists.Truly, there is no SelectedIndexChanged event for columns of type DropDownList, however, you can use the UpdateCell event of the grid in order to handle changed in the selected item in the drop down cell.

    You will need to check from which column the UpdateCell event was fired. This can be done using:

            if (e.Cell.Column.Key == "DropDown")

    where DropDown is the Key assigned to your drop down column. I would, however, recommend the WebCombo approach as it is cleaner.

    Please contact me if you have any questions.

    Best Regards,

    Petar Ivanov
    Developer Support Engineer
    Infragistics, Inc.

Reply Children
No Data