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

Cascading combobox / in-place forms event not firing

5 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
ToltingColtAcres asked on 25 Sep 2012, 01:01 PM
I am attempting to use a radgrid with  in-place editing of multiple cascading drop-downs. The user enters a term, which populates a combobox to get a list of 'preferred terms'... then, depending on the preferred term, the user can then select a classification.

Based on examples, found on the Telerik site, I crafted the below code. However, my ComboBox_SelectedIndexChanged Event handler never fires.

Any ideas why? I can step through the code and see the below code executes and attaches the event handlers to the combobox, and the drop-down does contain the correct list of values based on the user's entered term, but when the user selects a preferred term the event never fires (thus I never get to update the classification combobox based on the user's selection.)

What am I missing? Thanks!
protected void RadGrid_Terms_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        if (e.Item.DataItem != null)
        {
            String term = ((DataRowView)e.Item.DataItem)["Term"].ToString();
 
            SqlDataSource_PTCodeEdit.SelectCommand = "SELECT * FROM dbo.udt_PreferredTerm('" + term + "')";
            SqlDataSource_PTCodeEdit.Select(DataSourceSelectArguments.Empty);
 
            RadComboBox list = (e.Item as GridEditableItem)["FK_PT_GUID"].Controls[0] as RadComboBox;
 
            list.DataTextField = "PT_Name";
            list.DataValueField = "RowGuid_Key";
            list.DataSource = SqlDataSource_PTCodeEdit;
            list.DataBind();
            list.SelectedValue = ((DataRowView)e.Item.DataItem)["FK_PT_GUID"].ToString();
            list.Text = ((DataRowView)e.Item.DataItem)["PT_NAME"].ToString();
            list.AutoPostBack = true;
            list.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(ComboBoxControl_SelectedIndexChanged);
        }
    }
}

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Sep 2012, 06:03 PM
Hello,

Please try with below code.
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridEditableItem editedItem = e.Item as GridDataItem;
               GridEditManager editMan = editedItem.EditManager;
 
               GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("country"));
               RadComboBox ddList = editor.ComboBoxControl;
 
               ddList.DataSource = GenerateCountryData();
               ddList.DataTextField = "CountyID";
               ddList.DataValueField = "CountyName";
               ddList.DataBind();
               ddList.AutoPostBack = true;
               ddList.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(ddList_SelectedIndexChanged);
           }
       }
 
       void ddList_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
       {
            
       }
 
 
       protected DataTable GenerateCountryData()
       {
           DataTable dt = new DataTable();
           dt.Columns.Add("CountyID", typeof(int));
           dt.Columns.Add("CountyName", typeof(string));
 
           for (int i = 0; i < 11; i++)
           {
               dt.Rows.Add(i, "c" + i);
           }
 
           return dt;
       }


Thanks,
Jayesh Goyani
0
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
answered on 25 Sep 2012, 06:17 PM
Adopted your example into my code, attached below.

Same issue.

ComboBox SelectedChanged Event never fires, so my 2nd dependent combobox never gets updated values from the database for user selection.
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
     if (e.Item.DataItem != null)
     {
         String term = ((DataRowView)e.Item.DataItem)["Term"].ToString();
 
         SqlDataSource_PTCodeEdit.SelectCommand = "SELECT * FROM dbo.udt_Get_PT('" + term + "')";
         SqlDataSource_PTCodeEdit.Select(DataSourceSelectArguments.Empty);
 
         GridEditableItem editedItem = e.Item as GridDataItem;
         GridEditManager editMan = editedItem.EditManager;
 
         GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("FK_PT_GUID"));
         RadComboBox ddList = editor.ComboBoxControl;
 
         ddList.DataSource = SqlDataSource_PTCodeEdit;
         ddList.DataTextField = "PT_Name";
         ddList.DataValueField = "RowGUID_Key";
         ddList.DataBind();
         ddList.AutoPostBack = true;
         ddList.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(ComboBoxControl_SelectedIndexChanged);
    }
}
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Sep 2012, 08:17 AM
Hello,

Please try with below code/demo. This demo worked perfectly on my side.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
           OnItemCreated="RadGrid1_ItemCreated">
           <MasterTableView DataKeyNames="ID">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                   </telerik:GridBoundColumn>
                   <telerik:GridDropDownColumn DataField="Name" UniqueName="country" HeaderText="country">
                   </telerik:GridDropDownColumn>
                   <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
  {
      dynamic data = new[] {
          new { ID = 1, Name ="Name1",path="1.jpg"},
          new { ID = 2, Name = "Name2",path="2.jpg"},
          new { ID = 3, Name = "Name3",path="3.jpg"},
           new { ID = 4, Name = "Name4",path="2.jpg"},
          new { ID = 5, Name = "Name5",path="3.jpg"},
           new { ID = 6, Name ="Name1",path="1.jpg"},
          new { ID = 7, Name = "Name2",path="2.jpg"},
          new { ID = 8, Name = "Name3",path="3.jpg"},
           new { ID = 9, Name = "Name4",path="2.jpg"},
          new { ID = 10, Name = "Name5",path="3.jpg"},
           new { ID = 11, Name ="Name1",path="1.jpg"},
          new { ID = 12, Name = "Name2",path="2.jpg"},
          new { ID = 13, Name = "Name3",path="3.jpg"},
           new { ID = 14, Name = "Name4",path="2.jpg"},
          new { ID = 15, Name = "Name5",path="3.jpg"}
           
      };
      RadGrid1.DataSource = data;
  }
 
 
 
  protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
  {
 
      if (e.Item is GridEditableItem && e.Item.IsInEditMode)
      {
          GridEditableItem editedItem = e.Item as GridEditableItem;
          GridEditManager editMan = editedItem.EditManager;
 
          GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("country"));
          RadComboBox ddList = editor.ComboBoxControl;
 
          ddList.DataSource = GenerateCountryData();
          ddList.DataTextField = "CountyID";
          ddList.DataValueField = "CountyName";
          ddList.DataBind();
          ddList.AutoPostBack = true;
          ddList.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(ddList_SelectedIndexChanged);
      }
 
  }
 
  void ddList_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
  {
 
  }
 
 
  protected DataTable GenerateCountryData()
  {
      DataTable dt = new DataTable();
      dt.Columns.Add("CountyID", typeof(int));
      dt.Columns.Add("CountyName", typeof(string));
 
      for (int i = 0; i < 11; i++)
      {
          dt.Rows.Add(i, "c" + i);
      }
 
      return dt;
  }


Thanks,
Jayesh Goyani
0
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
answered on 26 Sep 2012, 12:33 PM

Yes... The demos work fine. I wasn't questioning whether or not the demos work. That's not my question.

Since my data source is an SQL database with 60,000 records, it isn't all that feasible that I replicate the demo code and manually create a DataTable in code to assign as the data source, as in the demo example you provided above.

My question was simply why the code I originally posted does not work, since effectively all I did was take the demo code and change the Datasource from a manually-created DataTable to an SqlDataSource which is dynamically populated.

Or, is it Telerik's assertion that their demo examples are incapable of being adapted to other, non-manually-created Datasources (e.g. SqlDataSources)?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Sep 2012, 05:04 PM
Hello,

i have tried with datasource and it works fine for me.

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                 
            }
 
 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem editedItem = e.Item as GridDataItem;
                GridEditManager editMan = editedItem.EditManager;
 
                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("country"));
                RadComboBox ddList = editor.ComboBoxControl;
 
                ddList.DataSource = SqlDataSource1;
                ddList.DataTextField = "ID";
                ddList.DataValueField = "Name";
                ddList.DataBind();
                ddList.AutoPostBack = true;
                ddList.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(ddList_SelectedIndexChanged);
            }
        }
 
        void ddList_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
             
        }


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikTestDataBaseConnectionString %>"
           SelectCommand="SELECT [ID], [Name] FROM [TelerikTest1]"></asp:SqlDataSource>

Note : i have tried with 100 records and its worked for me.

Please try with less data and check its work or not.

(If it is worked for you than please let me know i will try with more then 60,000 records)

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
Answers by
Jayesh Goyani
Top achievements
Rank 2
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
Share this question
or