SelectedIndexChanged Issue

3 posts, 0 answers
  1. Ian
    Ian avatar
    15 posts
    Member since:
    Feb 2012

    Posted 31 Jul 2012 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Aug 2012 Link to this post

    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.
  3. Ian
    Ian avatar
    15 posts
    Member since:
    Feb 2012

    Posted 01 Aug 2012 Link to this post

    G'Day Pricey, thanks mate it did the trick.  Ian.
Back to Top