Select Listbox Item based on Textbox input

Discussion in 'ASP .Net' started by RockNRoll, Aug 24, 2004.

  1. RockNRoll

    RockNRoll Guest

    Greetings,

    Can I select an item in a listbox based on user textbox entry and a submit
    button? Can you provide any code examples for what needs to occur when the
    user clicks submit? Thank you,

    -Dave
     
    RockNRoll, Aug 24, 2004
    #1
    1. Advertisements

  2. RockNRoll

    Karl Guest

    Do you mean when a user enters something in a textbox and hits a button, you
    want to have a value in a listbox selected? If so, then it's pretty easy.

    <asp:textbox id="txt" runat="Server" /> <asp:button id="btn"
    runat="server" Text="Go!" /><br /><br />
    <asp:dropdownlist id="ddl" runat="Server">
    <asp:ListItem Value="1">Canada</asp:ListItem>
    <asp:ListItem Value="2">United States</asp:ListItem>
    <asp:ListItem Value="3">Mexico</asp:ListItem>
    </asp:dropdownlist>


    And your codebehind could look something like:

    Protected WithEvents btn As System.Web.UI.WebControls.Button
    Protected txt As System.Web.UI.WebControls.TextBox
    Protected ddl As System.Web.UI.WebControls.DropDownList

    Private Sub btn_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btn.Click
    Dim textboxValue As String = txt.Text
    ddl.SelectedIndex =
    ddl.Items.IndexOf(ddl.Items.FindByValue(textboxValue))
    End Sub


    this is obviously a simple example.

    Karl

    "RockNRoll" <> wrote in message
    news:...
    > Greetings,
    >
    > Can I select an item in a listbox based on user textbox entry and a submit
    > button? Can you provide any code examples for what needs to occur when

    the
    > user clicks submit? Thank you,
    >
    > -Dave
    >
    >
     
    Karl, Aug 24, 2004
    #2
    1. Advertisements

  3. RockNRoll

    RockNRoll Guest

    Karl,

    Thank you for your response. I apprecaite it.

    -Dave


    "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
    message news:...
    > Do you mean when a user enters something in a textbox and hits a button,

    you
    > want to have a value in a listbox selected? If so, then it's pretty easy.
    >
    > <asp:textbox id="txt" runat="Server" /> <asp:button id="btn"
    > runat="server" Text="Go!" /><br /><br />
    > <asp:dropdownlist id="ddl" runat="Server">
    > <asp:ListItem Value="1">Canada</asp:ListItem>
    > <asp:ListItem Value="2">United States</asp:ListItem>
    > <asp:ListItem Value="3">Mexico</asp:ListItem>
    > </asp:dropdownlist>
    >
    >
    > And your codebehind could look something like:
    >
    > Protected WithEvents btn As System.Web.UI.WebControls.Button
    > Protected txt As System.Web.UI.WebControls.TextBox
    > Protected ddl As System.Web.UI.WebControls.DropDownList
    >
    > Private Sub btn_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles btn.Click
    > Dim textboxValue As String = txt.Text
    > ddl.SelectedIndex =
    > ddl.Items.IndexOf(ddl.Items.FindByValue(textboxValue))
    > End Sub
    >
    >
    > this is obviously a simple example.
    >
    > Karl
    >
    > "RockNRoll" <> wrote in message
    > news:...
    > > Greetings,
    > >
    > > Can I select an item in a listbox based on user textbox entry and a

    submit
    > > button? Can you provide any code examples for what needs to occur when

    > the
    > > user clicks submit? Thank you,
    > >
    > > -Dave
    > >
    > >

    >
    >
     
    RockNRoll, Aug 25, 2004
    #3
  4. RockNRoll

    BMan Guest

    BMan, Jun 12, 2005
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Prince
    Replies:
    2
    Views:
    3,561
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  2. =?Utf-8?B?RGF2aWQ=?=

    DropDownList: Select item based on record? (newbie)

    =?Utf-8?B?RGF2aWQ=?=, Nov 14, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    7,543
    =?Utf-8?B?RGF2aWQ=?=
    Nov 15, 2004
  3. Atreju
    Replies:
    1
    Views:
    5,386
    Anmol
    Jan 9, 2006
  4. QUASAR
    Replies:
    6
    Views:
    613
    QUASAR
    Jan 17, 2004
  5. rpress

    How to deselect item on single select listbox?

    rpress, Jan 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    2,143
    rpress
    Jan 9, 2006
  6. JamesB

    select listbox item programatically not working?

    JamesB, Dec 12, 2007, in forum: ASP .Net Web Controls
    Replies:
    8
    Views:
    400
    Jeremy
    Dec 15, 2007
  7. K. Lobe

    How do I select item in <SELECT>

    K. Lobe, Jul 2, 2003, in forum: ASP General
    Replies:
    3
    Views:
    240
    K. Lobe
    Jul 2, 2003
  8. hiroshi ochi
    Replies:
    3
    Views:
    461
    Hiroshi Ochi
    May 13, 2004
Loading...