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

Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Raymond Maillard - 05 May 2005 14:47 GMT
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
> Hi Raymond,
>
[quoted text clipped - 44 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Steven Cheng[MSFT] - 06 May 2005 02:04 GMT
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

Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)