VB.Net: Change selected item in one DropDownList using another?

GHoosdumGHoosdum Icrontian
edited October 2005 in Internet & Media
I have two DropDownList controls in an ASP Web Control that I've built for a project at work. They are mutually exclusive - or at least they should be. When an item is selected in one DropDownList, it should change the other DropDownList to the default value, a blank ListItem ("").

Unfortunately, I can't figure out how to do that.
I have placed, in the "SelectedIndexChanged" Sub for the first DropDownList item, the following pieces of code, and none of them have changed the selection in the second DropDownList:

List2.SelectedIndex.Equals(0)
List2.ClearSelection()
List2.SelectedItem.Value = ""

So my question is, what should I be using for this?

I feel bad about trying to get work-related help here (I don't want anyone else to do my job for me), but I don't know where else to turn - I tried several different searches on Google, but I must not be phrasing it properly to turn up what I'm looking for.

Comments

  • edited October 2005
    I sometimes use .NET for quick and dirty programs so I am not an expert.

    I am a C/C++ guy so VS.NET is somewhat painfull for me with the managed/unmanaged code.

    You may want to try;

    List2.SelectedIndex = 0; //The .Eqauls is a real eqauls test.
    List2.Text = "";

    I think that will clear the Text and set the SelectedIndex.

    CSwett
    GHoosdum wrote:
    I have two DropDownList controls in an ASP Web Control that I've built for a project at work. They are mutually exclusive - or at least they should be. When an item is selected in one DropDownList, it should change the other DropDownList to the default value, a blank ListItem ("").

    Unfortunately, I can't figure out how to do that.
    I have placed, in the "SelectedIndexChanged" Sub for the first DropDownList item, the following pieces of code, and none of them have changed the selection in the second DropDownList:

    List2.SelectedIndex.Equals(0)
    List2.ClearSelection()
    List2.SelectedItem.Value = ""

    So my question is, what should I be using for this?

    I feel bad about trying to get work-related help here (I don't want anyone else to do my job for me), but I don't know where else to turn - I tried several different searches on Google, but I must not be phrasing it properly to turn up what I'm looking for.
  • GargGarg Purveyor of Lincoln Nightmares Icrontian
    edited October 2005
    GHoosdum wrote:
    I have two DropDownList controls in an ASP Web Control that I've built for a project at work. They are mutually exclusive - or at least they should be. When an item is selected in one DropDownList, it should change the other DropDownList to the default value, a blank ListItem (""). ...

    I'll preface this by saying I only know VBA (VB 6.0) and I've never developed anything for the web :D

    Is there a "value" property for the DropDrownList control?
    Assuming your DropDownList controls are anything like combo boxes, I would just use:

    List2.Value = ""

    You may also want to change the SelectedItem after that, but I really don't know how that control works.
  • GHoosdumGHoosdum Icrontian
    edited October 2005
    I'll play around with your suggestions and see what happens. Thanks guys!

    I have another problem now - inside the same "SelectedIndexChanged" sub, I am giving a "Response.Redirect" command. This same exact command works in my "Click" sub for a button, but does not work on the action on the DropDownList. Is there something I need to set or change to make it possible for DropDownList actions to generate more "active" responses than simply setting variables? - The only thing I've gotten the "SelectedIndexChanged" sub to do that I need done is to set a Session variable, so I'm really puzzled here.

    Thanks!
Sign In or Register to comment.