J
JamesB
I am new to web stuff, having previously done forms based apps... anyway, my
web app currently has a listbox on a page that is populated from a database
table.
That works fine, I can see all the records, however I want to set the
listbox to the name of the logged in user.
I have done this:
String ln = Page.User.Identity.Name;
for (int i=0;i<lstNames.Items.Count;i++)
{
//Response.Write(" checking " +
lstNames.Items.Value.ToString().ToLower() + " against " + ln.ToLower());
if (lstNames.Items.Value.ToString().ToLower() ==
ln.ToLower())
{
Response.Write("Setting item " + i + " as selected.");
lstNames.SelectedIndex = i;
}
}
My response.write says it is setting the index to 20 (which is correct for
my username) however the listbox still shows the first name in the list.
Do I need to do something to force the listbox to redraw or is there some
other way? Seems like it should be so simple (and probably is...)!
Thanks
James
web app currently has a listbox on a page that is populated from a database
table.
That works fine, I can see all the records, however I want to set the
listbox to the name of the logged in user.
I have done this:
String ln = Page.User.Identity.Name;
for (int i=0;i<lstNames.Items.Count;i++)
{
//Response.Write(" checking " +
lstNames.Items.Value.ToString().ToLower() + " against " + ln.ToLower());
if (lstNames.Items.Value.ToString().ToLower() ==
ln.ToLower())
{
Response.Write("Setting item " + i + " as selected.");
lstNames.SelectedIndex = i;
}
}
My response.write says it is setting the index to 20 (which is correct for
my username) however the listbox still shows the first name in the list.
Do I need to do something to force the listbox to redraw or is there some
other way? Seems like it should be so simple (and probably is...)!
Thanks
James