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
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:
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 IvanovDeveloper Support EngineerInfragistics, Inc.
Hi Petar,
I am very new to Infragistics control.
I have similar requirement where I need to create a ultragrid within which two dropdownlists will be there.
And changing one dropdownlist another dropdown list will be populated accordingly based upon first dropdown values.
Please help me with an complete code example.
This is urgent
Thanks,