![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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[i].Value.ToString().ToLower() + " against " + ln.ToLower()); if (lstNames.Items[i].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 |
#3
| |||
| |||
|
|
On 12 Dec, 16:28, "JamesB" <jam... (AT) somewhere (DOT) com.net.com.net> wrote: 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[i].Value.ToString().ToLower() + " against " + ln.ToLower()); if (lstNames.Items[i].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 James, with all due respect you seem seriously confused about how web applications work. You must study it properly, in particular the execution model and how to control the property values and appearance of web server controls. Your use of response.write is totally inappropriate - once you've assigned values to the control items the rendering will take care of itself. I and others could propose a programmatic solution to meet your requirements but I fear it would be a waste of time. |
#4
| |||
| |||
|
|
Phil, pardon me for butting in, I don't suppose you considered the possibility that James' use of Response.Write was as a debugging tool, and not meant for production? I can't say of course, not being James, but couldn't I don't think it is useful to insult people. Jeremy |

#5
| |||
| |||
|
|
"Jeremy" <jeremy-nospam (AT) ninprodata (DOT) com> wrote in message news:OO5VQ4RPIHA.5360 (AT) TK2MSFTNGP03 (DOT) phx.gbl... Phil, pardon me for butting in, I don't suppose you considered the possibility that James' use of Response.Write was as a debugging tool, and not meant for production? I can't say of course, not being James, but couldn't I don't think it is useful to insult people. Jeremy Jeremy- you're right - the "reponse.write" was simply so I could check my lstNames.SelectedIndex = i; command was setting the index to the correct value I was expecting. I put that in when the listbox kept showing the first value. I probably should have explained that though ![]() Phil is right to a point - this is my first time messing around with web stuff, so there *is* new stuff to learn, but from what I can gather, setting the index of a control should still work? |
#6
| |||
| |||
|
|
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[i].Value.ToString().ToLower() + " against " + ln.ToLower()); if (lstNames.Items[i].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...)! |
#7
| |||
| |||
|
|
Phil, pardon me for butting in, I don't suppose you considered the possibility that James' use of Response.Write was as a debugging tool, and not meant for production? I can't say of course, not being James, but couldn't I don't think it is useful to insult people. Jeremy "Phil H" <goo... (AT) philphall (DOT) me.uk> wrote in message news:e67ca42b-9fcb-4693-aa6f-a982fe7301f0 (AT) i3g2000hsf (DOT) googlegroups.com... On 12 Dec, 16:28, "JamesB" <jam... (AT) somewhere (DOT) com.net.com.net> wrote: 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[i].Value.ToString().ToLower() + " against " + ln.ToLower()); if (lstNames.Items[i].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 James, with all due respect you seem seriously confused about how web applications work. You must study it properly, in particular the execution model and how to control the property values and appearance of web server controls. Your use of response.write is totally inappropriate - once you've assigned values to the control items the rendering will take care of itself. I and others could propose a programmatic solution to meet your requirements but I fear it would be a waste of time.- Hide quoted text - - Show quoted text - |
#8
| |||
| |||
|
|
Jeremy, James If my post came across as insulting then I'm very sorry, that certainly wasn't intended. I'm afraid it's the limitations of this form of communication (not face to face) and easy to give the wrong impression. That's ok - I'm aware it's all to easy for stuff to get misinterpreted in |
|
As to the problem James raised originally I have had time to look at it carefully and on reflection I now see more clearly how the response object was being used, so again sorry about that. However, I hope you will be pleased to know that I do have an answer as to why it wasn't working. Assigning a value to the selectedIndex property is fine but it depends critically on when it happens. That I'm afraid James is one of the quirks of web applications, they're not like windows apps. Web servers have a mind of their own when it comes to event handling. Makes sense - I guess there are 2 points of action to worry about as well, |
|
The answer is to do the assignment in the DropDownList "Databound" event. That occurs after the list has been loaded with data and control is reliquished to the programmer to modify its state if you wish. Perhaps you would like to give it a try. |
#9
| |||
| |||
|
|
"Phil H" <google (AT) philphall (DOT) me.uk> wrote in message news:e277823b-59c1-4e3e-8d8b-b980b43ba78a (AT) t1g2000pra (DOT) googlegroups.com... Jeremy, James If my post came across as insulting then I'm very sorry, that certainly wasn't intended. I'm afraid it's the limitations of this form of communication (not face to face) and easy to give the wrong impression. That's ok - I'm aware it's all to easy for stuff to get misinterpreted in this sort of channel! |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |