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

Create Programmatically - SelectedIndexChanged EventHandler

2 Answers 456 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kurt Boeckman
Top achievements
Rank 1
Kurt Boeckman asked on 20 Aug 2009, 06:17 PM
I have an aspx page that contains a RadToolBar.  In the RadToolBar, I create a RadComboBox at runtime.  I've set the AutoPostBack = true and I've plumbed in the SelectedIndexChanged event handler.  What I select a different item in the combo box, the page posts back but it does fire the event handler.  I've also tried code to wire up the the javascript code to handle the OnClientSelectedIndexChanged client side event.  That fires, but I'm not able to get any meaningful data our of the eventArgs.  Any suggestions would be appreciate

CODE TO WIRE UP SERVER SIDE SelectedIndexChanged event

RadToolBarButton

 

button = new RadToolBarButton("some string");

 

 

this.radToolBarGrid.Items.Add(button);

 

 

//Create a RadComboBox to track the drill activity

 

 

RadComboBox radCombo = new RadComboBox();

 

radCombo.AutoPostBack =

true;

 

radCombo.SelectedIndexChanged +=

new RadComboBoxSelectedIndexChangedEventHandler(radCombo_SelectedIndexChanged);

 

radCombo.Items.Add(

new RadComboBoxItem(item.Value, item.Key));
....

 

this

 

.radToolBarGrid.DataBind();

 

 

void radCombo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)

 

{

 

throw new NotImplementedException();

 

}

 

CODE TO WIRE UP THE OnClientSelectedIndexChanged client side event.

 

radCombo.OnClientSelectedIndexChanged =

"HandleDrill";

 

function

 

HandleDrill(sender, eventArgs) {

 

 

 

var item = eventArgs.get_item();

 

 

// alert the new item text and value.

 

 

 

 

alert(item.Text +

":" + item.Value);

 

}

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Aug 2009, 04:32 AM
Hi Kurt,

You could use the get_text() and get_value() methods in order to get the text and value of selected item in combobox correspondingly.

JavaScript:
 
<script type="text/javascript"
function HandleDrill(sender, eventArgs)  
   var item = eventArgs.get_item(); 
   alert(item.get_text() +":" + item.get_value()); // alert the new item text and value. 
</script> 

Checkout the following link which describes the most important methods of the client-side RadComboBox object:
RadComboBox object

-Shinu.
0
Kurt Boeckman
Top achievements
Rank 1
answered on 24 Aug 2009, 02:59 PM
That worked.  Thank you very much for your response.
Tags
ComboBox
Asked by
Kurt Boeckman
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kurt Boeckman
Top achievements
Rank 1
Share this question
or