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

want to add items on radcombobox from the clientsideselectedindexchanges event of another radcombobox inside the radgrid

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shankar mohan
Top achievements
Rank 1
shankar mohan asked on 29 Apr 2010, 03:40 PM
i ve two columns in radgrid
column a-radgriddropdowncolumn
column b-radgriddropdowncolumn

for scenario-- while selecting the value from column A i want to add items on Column B on Client selectedindexchanges event

 design  
 
<telerik:GridDropDownColumn    DataField="Year"       HeaderText="Year"      UniqueName="Year"    />   
                <telerik:GridDropDownColumn    DataField="Month"      HeaderText="Month"     UniqueName="Month"  />   
 
 
 
server side inside the item created  
 
 GridDropDownListColumnEditor drp = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor(strArray[k]);  
                        drp.ComboBoxControl.ID = "Yr";  
                        drp.ComboBoxControl.OnClientSelectedIndexChanged += "OnClientYearSelectedIndexChanged";  
                        RadComboBox txt = (item.EditManager.GetColumnEditor("Month") as GridDropDownListColumnEditor).ComboBoxControl;  
                        txt.ID = "Month";      
 
 
java script  
function OnClientYearSelectedIndexChanged(sender, eventArgs)  
{  
 var combo=$get(sender.get_id().replace("Yr", "Month"));            
        var comboItem = new Telerik.Web.UI.RadComboBoxItem();         
        comboItem.set_text("vanthudichi");          
        combo.get_items().add(comboItem);  
 
 
 
 
 

combo.get_item().add(comboItem)-->getting arror in this line like no property is available


i ve done the same for fetching the value on textbox from  dropdownvalue client selectedindexchanged event ,its working fine

javascript  
var txt = $get(sender.get_id().replace("pgm", "StartTime"));  
var txt2 = $get(sender.get_id().replace("pgm", "Endtime"));  
var txt3 = $get(sender.get_id().replace("pgm", "PrimeTime"));  
var txt4 = $get(sender.get_id().replace("pgm", "Contract_New_Rate"));  
 
if(res != null)  
{  
txt.value=res[0];  
txt2.value=res[1];  
txt3.value=res[2];  

sever side item created  
 
 
GridDropDownListColumnEditor drp = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor(strArray[k]);  
                        drp.ComboBoxControl.ID = "pgm";                                                                                                  
                        drp.ComboBoxControl.OnClientSelectedIndexChanged += "OnClientSelectedIndexChanged";  
 
 
                        TextBox txt = (item.EditManager.GetColumnEditor("StartTime") as GridTextBoxColumnEditor).TextBoxControl;  
                        txt.ID = "StartTime";  
                        TextBox txt2 = (item.EditManager.GetColumnEditor("Endtime") as GridTextBoxColumnEditor).TextBoxControl;  
                        txt2.ID = "Endtime";  
                        TextBox txt3 = (item.EditManager.GetColumnEditor("PrimeTime") as GridTextBoxColumnEditor).TextBoxControl;  
                        txt3.ID = "PrimeTime";  
                        TextBox txt4 = (item.EditManager.GetColumnEditor("Contract_New_Rate") as GridTextBoxColumnEditor).TextBoxControl;  
                        txt4.ID = "Contract_New_Rate";  
                        drp.ComboBoxControl.Filter = RadComboBoxFilter.StartsWith;  
                        drp.ComboBoxControl.EmptyMessage = "--Select--";      
 


but the same is not working for dropdown to dropdown binding

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Apr 2010, 08:32 AM
Hello,

One suggestion would be saving the ClientID of the second combobox in a HiddenField and access the combo from clientside to insert new item.

Here is the code snippet  to store the ClientID of comboox rendered in EditMode:
 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem edititem = (GridEditFormItem)e.Item; 
            RadComboBox combo1 = (RadComboBox)edititem["Dropdown1"].Controls[0]; 
            combo1.OnClientSelectedIndexChanged = "ClientSelectedIndexChanged"
            RadComboBox combo2 = (RadComboBox)edititem["Dropdown2"].Controls[0]; 
            HiddenField1.Value = combo2.ClientID; 
        } 
    } 

And you can access the combo in the event handler by using following client code:
 
<script type="text/javascript"
    function ClientSelectedIndexChanged() { 
        var combo21 = $find(document.getElementById('HiddenField1').value); 
        var comboItem = new Telerik.Web.UI.RadComboBoxItem(); 
        comboItem.set_text("item1"); 
        combo21.get_items().add(comboItem); // Add new item 
    } 
</script> 

Hope this suggestion helps,
Shinu.
0
shankar mohan
Top achievements
Rank 1
answered on 30 Apr 2010, 11:10 AM
thank Q

i tried like this and its working fine for me
 function OnClientYearSelectedIndexChanged(sender, eventArgs)  
{   
var ComboboxTelerik.Web.UI.RadComboBox.ComboBoxes[3];  -->ve to specify the control index   
 var comboItemnew Telerik.Web.UI.RadComboBoxItem();    
        Combobox.trackChanges();  
        Combobox.clearItems();     
        comboItem.set_text("Sampletext");   
        Combobox.get_items().add(comboItem);     
        Combobox.commitChanges();          


Tags
Grid
Asked by
shankar mohan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
shankar mohan
Top achievements
Rank 1
Share this question
or