p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Clearing the Dregs from a Dropdown menu (http://p2p.wrox.com/showthread.php?t=47646)

rit01 September 11th, 2006 06:07 AM

Clearing the Dregs from a Dropdown menu
 
Hi All

I have 2 dropdown menus that are databound. The second dropdown list is bound to the first dropdown menu's selectedvalue.

I have created the databinding within the code behind for various reasons and for some reason when selecting a different value from within my first menu, the second menu updates accordingly but still stores the previous items too rather than refreshing and just storing the new selected data.

When I set up the databinding using SQLDatasource controls the second list updates without storing the dregs.

Please could anyone let me know what I could be missing...
Code:

Protected Sub Menu1_SelectedIndexChanged
     (ByVal sender As Object, ByVal e As System.EventArgs)

        'database connection class/ function
        Dim Menu2Populate As New dbclass()
 
        Menu2Populate.Sproc = "strored procedure"
        Menu2Populate.CustomerID = Menu1.SelectedValue
        Menu2.DataSource = Menu2Populate.RetrieveMenu2data
        Menu2.DataBind()

    End Sub

Many thanks

Rit

rit01 September 11th, 2006 06:26 AM

HI All

I figured out a solution if anyone is interested...

What I did was used Menu2.Items.Clear() prior to calling my databind.

Code:


Protected Sub Menu1_SelectedIndexChanged
     (ByVal sender As Object, ByVal e As System.EventArgs)

       Menu2.Items.Clear()

        'database connection class/ function
        Dim Menu2Populate As New dbclass()
 
        Menu2Populate.Sproc = "strored procedure"
        Menu2Populate.CustomerID = Menu1.SelectedValue
        Menu2.DataSource = Menu2Populate.RetrieveMenu2data
        Menu2.DataBind()

    End Sub

Basically clears the menu before populating again.

If there is a better way of treating this please feel free to educate me.

Thanks

Rit


All times are GMT -4. The time now is 05:42 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.