Hi,
I saw a post or sample code somewhere on the Telerik site on how to filter template columns which are lookup columns, based on another lookup column value, I now cannot find it to reference it. But it is not working and I cannot see why.
Basically, my grid is for questions, under each question there are four lookup columns. The values in lookups 2, 3 and 4 should be filtered according to the value selected in lookup column 1. This is working fine but only for editing existing questions. When creating a new question the code is firing the events but other lookups are never filtered. This is what I am doing:
Any ideas or help greatly appreciated.
Thanks
I saw a post or sample code somewhere on the Telerik site on how to filter template columns which are lookup columns, based on another lookup column value, I now cannot find it to reference it. But it is not working and I cannot see why.
Basically, my grid is for questions, under each question there are four lookup columns. The values in lookups 2, 3 and 4 should be filtered according to the value selected in lookup column 1. This is working fine but only for editing existing questions. When creating a new question the code is firing the events but other lookups are never filtered. This is what I am doing:
Any ideas or help greatly appreciated.
Thanks
protected void RadGridQuestions_ItemCreated(object sender, GridItemEventArgs e) { if ((e.Item is GridEditFormItem || e.Item is GridEditFormInsertItem) && e.Item.IsInEditMode) { if (e.Item.OwnerTableView.Columns.FindByUniqueNameSafe("Test_Type_Id") == null) return; RadComboBox ddlTestType = (e.Item as GridEditableItem)["Test_Type_Id"].Controls[0] as RadComboBox; // Attach SelectedIndexChanged event for the dropdownlist control ddlTestType.AutoPostBack = true; ddlTestType.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(TestTypeOfQuestion_SelectedIndexChanged); TestTypeOfQuestion_SelectedIndexChanged(ddlSubObjective, null); ddlTestType.PreRender += new EventHandler(ddlTestType_PreRender); } } private void ddlTestType_PreRender(object sender, EventArgs e) { TestTypeOfQuestion_SelectedIndexChanged(sender, null); } /// <summary> /// Changed test type so update objective and sub objective only relevant for that exam type /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TestTypeOfQuestion_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) { // First reference the edited grid item through the NamingContainer attribute GridEditableItem editedItem = (sender as RadComboBox).NamingContainer as GridEditableItem; // The dropdown list will be the first control in the Controls collection of the corresponding cell string strTestTypeId = (editedItem["Test_Type_Id"].Controls[0] as RadComboBox).SelectedValue; if (string.IsNullOrEmpty(strTestTypeId)) return; RadComboBox ddlKeyElement = editedItem["Question_Category_Id"].Controls[0] as RadComboBox; SqlDataSourceQuestionCatLookupEdit.SelectParameters["Test_Type_Id"].DefaultValue = strTestTypeId; ddlKeyElement.ClearSelection(); ddlKeyElement.DataSource = SqlDataSourceQuestionCatLookupEdit; ddlKeyElement.DataBind(); RadComboBox ddlObjective = editedItem["Objective_Id"].Controls[0] as RadComboBox; SqlDataSourceObjectiveLookupEdit.SelectParameters["Test_Type_Id"].DefaultValue = strTestTypeId; ddlObjective.ClearSelection(); ddlObjective.DataSource = SqlDataSourceObjectiveLookupEdit; ddlObjective.DataBind(); RadComboBox ddlSubObjective = editedItem["Sub_Objective_Id"].Controls[0] as RadComboBox; SqlDataSourceSubObjectiveLookupEdit.SelectParameters["Test_Type_Id"].DefaultValue = strTestTypeId; ddlSubObjective.ClearSelection(); ddlSubObjective.DataSource = SqlDataSourceSubObjectiveLookupEdit; ddlSubObjective.DataBind(); }