This is a migrated thread and some comments may be shown as answers.

Cascading Dropdowns in EditFormTemplate

5 Answers 296 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 08 Nov 2010, 04:23 PM
Hello, I am having an issue with a custom edit form for rad grid.  I have cascading drop downs in an edit form template, basically, user selects a state and then the city dropdown pre populates with cities in that state.  I bind the initial item lists in the ItemDataBound event like I saw in some examples.  I have no issues pre populating the drop downs with the initial lists and selected values, however if a user changes the value of the States drop down, it causes a postback (which it should) but it resets the whole form back to the original values.

<MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Width="600" DataKeyNames="Id">
<EditFormSettings EditFormType="Template"   >
<FormTemplate  >
<table cellspacing="8">
<tr>
<td class="style2">Title:</td>
<td>
    <telerik:RadTextBox ID="txtTitle" Visible="true" Text='<%# DataBinder.Eval( Container, "DataItem.Title" ) %>' MaxLength="100" Width="400" runat="server">
    </telerik:RadTextBox>
</td>
</tr>
<tr>
<td class="style1" valign="top" >State:</td>
<td>
    <telerik:RadComboBox ID="RadComboBoxState" runat="server">
    </telerik:RadComboBox>
 
</td>
</tr>
<tr>
<td class="style1" valign="top" >City:
 
</td>
<td>
    <telerik:RadComboBox ID="RadComboBoxCity" runat="server">
    </telerik:RadComboBox>
 
</td>
</tr>

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
       {
           GridEditFormItem editFormItem = e.Item as GridEditFormItem;
           GridDataItem parentItem = editFormItem.ParentItem;
 
           Literal debug = (Literal)editFormItem.FindControl("ltr_debug");
 
           int _EntityId = Convert.ToInt32(parentItem["OwnerEntityId"].Text);
 
           //*******************************
           //Load states
           //*******************************
           RadComboBox cbStates = editFormItem.FindControl("RadComboBoxState") as RadComboBox;
           DataTable dtStates = ApplicationInterface.GetActiveStates();
           cbStates.DataSource = dtStates;
           cbStates.DataValueField = "id";
           cbStates.DataTextField = "name";
           cbStates.DataBind();
           cbStates.SelectedValue = parentItem["SelectedState"].Text;
           cbStates.AutoPostBack=true;
           cbStates.SelectedIndexChanged += new System.EventHandler(StateSelected);
 
           //*******************************
           //Load cities
           //*******************************
           RadComboBox lbCities= (RadComboBox)editFormItem.FindControl("RadComboBoxCity");
           DataTable dtCitiesByState = ApplicationInterface.GetCitiesForState(parentItem["SelectedState"].Text);
           lbCities.DataSource = dtCitiesByState;
           lbCities.AutoPostBack = true;
           lbCities.DataValueField = "id";
           lbCities.DataTextField = "name";
           lbCities.DataBind();
           lbCities.SelectedValue = parentItem["SelectedCity"].Text;
         
       }
   }

protected void StateSelected(object sender, EventArgs e)
{
   RadComboBox dc = (RadComboBox)sender;
 
   GridEditFormItem editedItem = dc.NamingContainer as GridEditFormItem;
   RadComboBox cities=editedItem.FindControl("RadComboBoxCity") as RadComboBox;
   ...
   ..Binding code here
 
 }


So the edit form populates correctly, user changes some text boxes etc... but if they select a different state the whole form resets.  Is there anything special I need to do to use cascading combo boxes with async postbacks in my edit form.  I have read some other posts but I cant find anything that replicates the issue I am having.

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 08 Nov 2010, 05:47 PM
Hello Joe,

I recommend that you examine this code library which shows how to use related RadComboBoxes for Insert and Update operations in RadGrid.

I hope this gets you started properly.

Best wishes,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Joe
Top achievements
Rank 1
answered on 18 Nov 2010, 12:09 AM
Hi, I have reviewed this but the example provided uses edit columns.  I am trying to use and EditFormTemplate.  DO you have an example of cascading drop downs in an editformtemplate scenario.  Thanks
0
Pavlina
Telerik team
answered on 19 Nov 2010, 01:19 PM
Hello Joe,

In this case, you can reference the cell(s) which hold the combo box control(s). For additional information on this topic, please refer to the following article:

http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

I hope this gets you started properly.

Best wishes,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Lee
Top achievements
Rank 1
answered on 12 Feb 2011, 08:20 PM
Hi Joe,

You might have found a solution to this already but I thought it was worth posting a solution anyway. I have 2 Radcomboboxes, Locations and Warehourse. When a location is selected, the warehouses at that location are loaded.

I put a textbox on the form called CurrentLocation with visible set to false. I added the following code on the Locations SelectIndexChanged event:
protected void RadComboBox5_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    if (RadGrid1.MasterTableView.IsItemInserted != false)
    {
        GridEditFormInsertItem insertItem = (GridEditFormInsertItem)(sender as RadComboBox).NamingContainer;
        RadComboBox ddlList = (RadComboBox)insertItem.FindControl("RadCombox5");
        CurrentLocation.Text = ddlList.SelectedValue ;
    }
    else
    {
        GridEditableItem editedItem = (GridEditableItem)(sender as RadComboBox).NamingContainer;
        RadComboBox ddlList = (RadComboBox)editedItem.FindControl("RadComboBox5");
        CurrentLocation.Text = ddlList.SelectedValue;
    }
}

The Location RadComboBox does an autopostback and the appropriate warehouses are loaded.

Regards, Lee

0
Pavlina
Telerik team
answered on 16 Feb 2011, 04:08 PM
Hi Lee,

Thank you for sharing your solution with us and the community! It will certainly help other people searching similar functionality.

Kind regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Joe
Top achievements
Rank 1
Lee
Top achievements
Rank 1
Share this question
or