Raymond Maillard
5/5/2005 1:47:00 PM
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]" <v-schang@online.microsoft.com> wrote in message
news:%23Ld6StTUFHA.3052@TK2MSFTNGXA01.phx.gbl...
> 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.)
>