locked
Calling a DropDownLIst's Selectedindexchange event on pageload RRS feed

  • Question

  • User-266149547 posted

    Good Morning,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    I have an ASP.NET 2.0 that contains a dropdown list used to filter records based on a group number.  For example, if the dropdown list selectedvalue = 3, only records containing a 3 in the group number column of the table will display.  This is working perfectly.  However, when the page first displays the default value is 1, and the records from group 1 do NOT display unless I trigger the dropdown list event.  I am trying to get the records to display for group 1 when the page first opens to avoid having to use the dropdown when the page loads. 

    <o:p> </o:p>

    The “drop down list control” filters records in a “data list” control. 

    <o:p> </o:p>

    I am thinking of writing a piece of VB.NET code to automatically call the Drop Down List’s SelectIndexChanged event on the page so the user does not have to do it.

    <o:p> </o:p>

    My question is, how do I call that event from the “On Page Load”  or, is there a better way to do this? 

    <o:p> </o:p>

    <o:p> </o:p>

    Thanks very much for any help with this.

    Thursday, January 4, 2007 10:52 AM

All replies

  • User-837620913 posted

    Just make a call to the dropdownlist's method in the Page_Load:

    myDropDownList_SelectedIndexChanged( this, EventArgs.Empty )

     

    Thursday, January 4, 2007 2:26 PM
  • User-266149547 posted

    Let me rephrase this:

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    I want the click event of “Button1” to “TRIGGER” the action of a user selecting a value from the dropdown list and firing the code behind the dropdown.  This particular event will trigger the dropdown to select the value = 1 and fire the code behind.  Does that make sense?

    <o:p> </o:p>

    Thank you very much.

     

    Thursday, January 4, 2007 3:43 PM
  • User-266149547 posted

    Actually, I think I need to call and additional post back to “refresh the page” .  That is what I think I am looking for.  Can I tell the page to do a “double postback”? 

     
    Thursday, January 4, 2007 4:01 PM
  • User-266149547 posted

    I am not sure what the best solution is.  I just want the records to show up on the first load of the page without having to do the extra action of selecting from the dropdownlist.  The default value is 1, but I have to select the value from the list and cause a postback for the filtered records to appear the first time the page is loaded.  Anytime after the first load is fine, just that first load is coming up empty.

    Thursday, January 4, 2007 4:11 PM
  • User-524013004 posted

    As per Darrell’s earlier post.

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    Partial Class Example

        Inherits System.Web.UI.Page<o:p></o:p>

    <o:p> </o:p>

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<o:p></o:p>

    <o:p> </o:p>

            If Not Me.IsPostBack Then<o:p></o:p>

    <o:p> </o:p>

                ' Where the DropDownlist ID is DropDownList1<o:p></o:p>

                Me.DropDownList1.SelectedValue = 3<o:p></o:p>

                ' Calls the method directly passing the appropriate sender<o:p></o:p>

                Me.DropDownList1_SelectedIndexChanged(Me.DropDownList1, System.EventArgs.Empty)<o:p></o:p>

            End If<o:p></o:p>

    <o:p> </o:p>

        End Sub<o:p></o:p>

    <o:p> </o:p>

        Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged<o:p></o:p>

    <o:p> </o:p>

            ' presuming you get your data here by the selected index - provided for breakpoint only (remove)<o:p></o:p>

            Dim index As Integer = Me.DropDownList1.SelectedIndex<o:p></o:p>

    <o:p> </o:p>

        End Sub<o:p></o:p>

    End Class<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    Rgds,

    Martin.

    Sunday, January 7, 2007 5:51 PM
  • User1820087368 posted

    i want to add evnet for dropdownlist in asp.net ( vb.net )

    when i use addhandler then i can tsee my dropdownlist ? its set to run at server, other than addhandler i can see cmbmydropdown?plz help me  

    Wednesday, January 16, 2008 11:04 AM
  • User332438825 posted

    i have tried this in my application but it doesnt work.

    in my application i have first dropdown box which gets filled using sqldatasource and according to value in that the second dropdown box gets filled using in DropdownBox1_SelectedIndexChanged event, and in the DropDownBox2_SelectedIndexChanged event other textboxs gets filled,

    all i want is when the page loads for the first time when the selected index of the first dropdownbox is 0 the rest controlls get filled automatically but somehow its not working for me, i have tried adding DropdownList1_SelectedIndexChanged(sender, e) in the Page_Load event and also try to set the selected Index for the dropdown list in the page load but none of these working, please help, guide me through this.

    Thank you so much.

     

    Tuesday, October 19, 2010 2:27 PM
  • User332438825 posted

    finally done with this.  

    Thursday, January 20, 2011 12:21 PM
  • User1214642152 posted

    if possible if you could share your solution please

    Saturday, April 9, 2011 4:36 AM