finding the correct item in a mobile selection list

Discussion in 'ASP .Net Mobile' started by Raymond Maillard, May 2, 2005.

  1. I have a form that searches for a particular piece of equipment and allows
    the user to edit the record when a command button is pressed.
    The active form then loads a dataset with model information in a dropdown.
    How do I prgrammatically set the value in the selectionlist so that it
    represents the value for the model as defined in the equipment record?

    eg

    Serial Number: [ ]
    Model: [ selectionlist as a drop down control ]

    I need the model to default to the model id representing the equipment
    model.

    I have using

    control.selection.value = imid.tostring

    which does not work. imid is the field containing the model id.




    Regards
    Raymond Maillard, May 2, 2005
    #1
    1. Advertising

  2. Hi Raymond,

    Based on my understanding, the question is: How to select a specific model
    in a dropdownlist web server control in asp.net? Please correct me if I
    have misunderstood it.

    To do that, we need to get the SelectedIndex of the correct item. And then
    call:
    Control.SelectedIndex = ** to set it.

    MSDN link of it is:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
    vbtsksettingselectioninlistbox.asp

    Thanks very much.

    Best regards,
    Yanhong Huang
    Microsoft Community Support

    Get Secure! ¨C www.microsoft.com/security
    Register to Access MSDN Managed Newsgroups!
    -http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
    p&SD=msdn

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Yan-Hong Huang[MSFT], May 3, 2005
    #2
    1. Advertising

  3. Hi Raymond,

    By the way,
    SelectedValue property can also to be used.

    Please refer to:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfsystemwebuiwebcontrolslistcontrolclasstopic.asp

    Best regards,
    Yanhong Huang
    Microsoft Community Support

    Get Secure! ¨C www.microsoft.com/security
    Register to Access MSDN Managed Newsgroups!
    -http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
    p&SD=msdn

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Yan-Hong Huang[MSFT], May 3, 2005
    #3
  4. Thanks for the response. I need to have the selectionlist primed with a
    value supplied to it so that it displays that value when the form is loaded.
    My selectionlist uses a dataset that has 15 records in it. Depending on how
    the form is opened, I may pass to it a value for the 5th record for example.
    I want the form to open with the 5th record displayed/selected in the
    selectionlist and not the first record.


    Regards



    "Yan-Hong Huang[MSFT]" <> wrote in message
    news:...
    > Hi Raymond,
    >
    > Based on my understanding, the question is: How to select a specific model
    > in a dropdownlist web server control in asp.net? Please correct me if I
    > have misunderstood it.
    >
    > To do that, we need to get the SelectedIndex of the correct item. And then
    > call:
    > Control.SelectedIndex = ** to set it.
    >
    > MSDN link of it is:
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
    > vbtsksettingselectioninlistbox.asp
    >
    > Thanks very much.
    >
    > Best regards,
    > Yanhong Huang
    > Microsoft Community Support
    >
    > Get Secure! ¨C www.microsoft.com/security
    > Register to Access MSDN Managed Newsgroups!
    > -http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
    > p&SD=msdn
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    Raymond Maillard, May 3, 2005
    #4
  5. Hi Raymond,

    Is what you're wantting to do just like

    bind the SelectList with datasource in Page_Load and then set the initial
    selectedIndex to a certain item according to a given value? (Please feel
    free to let me know if I misunderstand).

    If so, I think we can make use of the SelectedIndex property of the
    SelectList control, this property is used to speicfy the current
    selectedItem's index. Then, another problem is how to get the correct
    Index of the Item we want to set as current selectedItem according to a
    given value. This can be done through the SelectList control's "Items"
    collection, the Items property is a MobileListItemCollection which support
    the following method:

    MobileListItemCollection.IndexOf( MobileListItem item );

    which find the certain ListItem's index in the collection according to the
    provided ListItem instance. In our scenario, we can construct a
    MobileListItem through the given value and search in the colleciton. For
    example:

    private void Bind_List()
    {
    string[] items = {"aaa","bbb","ccc","ddd","eee","fff","ggg"};

    lstName.DataSource = items;

    lstName.DataBind();

    string val = "eee";
    int index = lstName.Items.IndexOf( new MobileListItem(val,val));

    lstName.SelectedIndex = index;
    }

    the above code bind a SelectList with some datas and then specify the
    initial selected value as "eee" (not the default first one).

    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], May 5, 2005
    #5
  6. Your understanding of the situation is correct. However, after some research
    and trial I was able to solve the problem using the itemdatabind event as
    follows:

    Private Sub cboProd_ItemDataBind(ByVal sender As Object, ByVal e As
    System.Web.UI.MobileControls.ListDataBindEventArgs) Handles
    cboProd.ItemDataBind

    If e.ListItem.Value = CType(iMid, String) Then

    cboProd.Selection.Text = CType(e.ListItem.Text, String)

    Else

    cboProd.SelectedIndex = 0

    End If

    End Sub





    imid is the variable used to prime the selection.



    Thanks to everyone that responded.



    Regards





    "Steven Cheng[MSFT]" <> wrote in message
    news:%...
    > Hi Raymond,
    >
    > Is what you're wantting to do just like
    >
    > bind the SelectList with datasource in Page_Load and then set the initial
    > selectedIndex to a certain item according to a given value? (Please feel
    > free to let me know if I misunderstand).
    >
    > If so, I think we can make use of the SelectedIndex property of the
    > SelectList control, this property is used to speicfy the current
    > selectedItem's index. Then, another problem is how to get the correct
    > Index of the Item we want to set as current selectedItem according to a
    > given value. This can be done through the SelectList control's "Items"
    > collection, the Items property is a MobileListItemCollection which support
    > the following method:
    >
    > MobileListItemCollection.IndexOf( MobileListItem item );
    >
    > which find the certain ListItem's index in the collection according to the
    > provided ListItem instance. In our scenario, we can construct a
    > MobileListItem through the given value and search in the colleciton. For
    > example:
    >
    > private void Bind_List()
    > {
    > string[] items = {"aaa","bbb","ccc","ddd","eee","fff","ggg"};
    >
    > lstName.DataSource = items;
    >
    > lstName.DataBind();
    >
    > string val = "eee";
    > int index = lstName.Items.IndexOf( new MobileListItem(val,val));
    >
    > lstName.SelectedIndex = index;
    > }
    >
    > the above code bind a SelectList with some datas and then specify the
    > initial selected value as "eee" (not the default first one).
    >
    > Hope helps. Thanks,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    Raymond Maillard, May 5, 2005
    #6
  7. Cool Raymond!

    Glad that you've found your own solution on this. Also, if sometimes we
    don't want to intercept the databinding event, you can consider the
    "indexof" means I mentioned. Anyway, thanks again for your posting!

    Good Luck!

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], May 6, 2005
    #7
    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 Niederberger
    Replies:
    2
    Views:
    16,452
    Christian Kaufhold
    Jan 7, 2005
  2. chen selina
    Replies:
    0
    Views:
    1,257
    chen selina
    Jul 13, 2010
  3. QUASAR
    Replies:
    6
    Views:
    409
    QUASAR
    Jan 17, 2004
  4. curiousity

    HOWTO autopost the selection list upon selection

    curiousity, Nov 21, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    260
    curiousity
    Nov 21, 2003
  5. Roy Smith
    Replies:
    3
    Views:
    346
    Roy Smith
    May 21, 2012
Loading...

Share This Page