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

SelectedIndexChanged Issue

2 Answers 113 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 31 Jul 2012, 10:33 PM

Hi guys, I am having trouble doing something I thought would be simple.

The scenario:
1. A combobox on a page with autopostback set to true and a sub in the codebehind that I want to fire whenever the combobox changes.
Protected Sub cmbxHerbicide_SelectedIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles cmbxHerbicide.SelectedIndexChanged
Dim con As New S
.............
..............
End Sub

2. On page load I grab a querystring and use it to change the combobox.
cmbxHerbicide.SelectedValue = Request.QueryString("ActiveID")

Ok, when I run this the combobox is changed as expected but the sub does not fire.
So I thought I would try:

cmbxHerbicide.SelectedValue = Request.QueryString("ActiveID")
cmbxHerbicide_SelectedIndexChanged(e, e)

This produces an error.
Unable to cast object of type 'System.EventArgs' to type 'Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs'

How do I get around this? 

I had expected that if I had AutoPostback set to true, and I changed the selection then the SelectedIndexChanged would fire.

What event args do I need to send?

Cheers

Ian
PS. The sub fires fine if I manually change the combobox.  The reason I am doing it in this way is that sometimes I want to run the code from a value pulled from a querystring, but once the user is on the page they can then go and select other values.  A worst case scenario is that I duplicate lots of code, I don't want to do that, the simple solution is to change the selection and call the sub.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Aug 2012, 06:00 AM
Hi Ian,

You can pass the arguments for SelectedIndexChangedEvent as follows.

VB:
RadComboBox1.SelectedValue = "Value"
Dim args As RadComboBoxSelectedIndexChangedEventArgs = New RadComboBoxSelectedIndexChangedEventArgs("", "", "", "")
RadComboBox1_SelectedIndexChanged(RadComboBox1, args)

Hope this helps.

Thanks,
Princy.
0
Ian
Top achievements
Rank 1
answered on 01 Aug 2012, 07:32 PM
G'Day Pricey, thanks mate it did the trick.  Ian.
Tags
ComboBox
Asked by
Ian
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ian
Top achievements
Rank 1
Share this question
or