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. Advertising

  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. Advertising

  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. Advertising

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,311
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  2. QUASAR
    Replies:
    6
    Views:
    407
    QUASAR
    Jan 17, 2004
  3. rpress

    How to deselect item on single select listbox?

    rpress, Jan 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    1,434
    rpress
    Jan 9, 2006
  4. JamesB

    select listbox item programatically not working?

    JamesB, Dec 12, 2007, in forum: ASP .Net Web Controls
    Replies:
    8
    Views:
    254
    Jeremy
    Dec 15, 2007
  5. hiroshi ochi
    Replies:
    3
    Views:
    288
    Hiroshi Ochi
    May 13, 2004
Loading...

Share This Page