DropDownList - pre-position to an entry

Discussion in 'ASP .Net Web Controls' started by Larry, Jan 17, 2004.

  1. Larry

    Larry Guest

    If I have a Dropdownlist box with several items in it, and I want to display that listbox to the browser with an entry already selected (which may not necessarily be the last item selected by the user), is there a method that does this?
    Larry, Jan 17, 2004
    #1
    1. Advertising

  2. Hi,

    Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
    assisting you on this issue.
    Based on my understanding, you have a Dropdownlist on your web form, when
    user visit your web page, you want to set one of the item in your list to
    be selected.
    If I misunderstand you, please feel free to point me out.

    =============================

    Actually, I think you can use DropDownList.SelectedIndex to set the default
    selected item's index. Do like this:

    private void Button1_Click(object sender, System.EventArgs e)
    {
    DropDownList1.SelectedIndex=2;
    }

    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 17, 2004
    #2
    1. Advertising

  3. Larry

    Larry Guest

    That's all I needed. Thanks
    Larry, Jan 18, 2004
    #3
  4. Larry

    Simon Guest

    Jeffrey,

    I'm doing something similar, except I'm using ddl.SelectedValue. On Page_Load this works fine, but if I try the same code elsewhere on the form (ie: a Cancel button to reset the values) then the dropdownlist will always revert to the first element in the list.

    Code:
    MyDataSet.Merge((DataSet)Session["MyStoredDataSet"]);
    MyDataView.RowFilter = "State = " + Session["StoredState"].ToString();
    ddlState.DataBind(); // Where SelectedValue is databound to State in MyDataView.


    On Page_Load, fine. Elsewhere, uh-uh.

    Can you help?

    Simon.


    ----- \"Jeffrey Tan[MSFT]\" wrote: -----


    Hi,

    Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
    assisting you on this issue.
    Based on my understanding, you have a Dropdownlist on your web form, when
    user visit your web page, you want to set one of the item in your list to
    be selected.
    If I misunderstand you, please feel free to point me out.

    =============================

    Actually, I think you can use DropDownList.SelectedIndex to set the default
    selected item's index. Do like this:

    private void Button1_Click(object sender, System.EventArgs e)
    {
    DropDownList1.SelectedIndex=2;
    }

    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Simon, Jan 20, 2004
    #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. Rocky Moore
    Replies:
    7
    Views:
    1,731
    mikeb
    Jan 14, 2004
  2. =?Utf-8?B?S2V2aW4gQnVydG9u?=

    Pre-Send Request Headers, Pre-Send Request Content

    =?Utf-8?B?S2V2aW4gQnVydG9u?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,042
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  3. Wladimir Borsov
    Replies:
    7
    Views:
    470
    Raymond Loman
    May 5, 2004
  4. Juha Nieminen
    Replies:
    3
    Views:
    1,144
    Juha Nieminen
    Feb 22, 2008
  5. Chris M. Thomasson
    Replies:
    10
    Views:
    647
    Nobody
    Aug 29, 2009
Loading...

Share This Page