473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

listbox and dropdownlist bug in VS2005 webdeveloper??

28
hi,
i'm working on a website with lots of webcontrols on visual studio 2005
i'm trying to read the text on a drop down list but it always gives me the initial text and not the text that is selected by the user?
is this a bug or is there another way about it?
ive tried this

Expand|Select|Wrap|Line Numbers
  1. Dim A as string = dropdownlist1.selecteditem.text 'gives initial text
  2. Dim A as string = dropdownlist1.text                    'also gives initial text
  3.  
???
Jun 21 '07 #1
9 1374
kenobewan
4,871 Expert 4TB
Try selected value and see what happens.
Jun 21 '07 #2
maghi85
28
Try selected value and see what happens.
doesn't work either... gives the initial value =(
Jun 21 '07 #3
gomzi
304 100+
hi,
i'm working on a website with lots of webcontrols on visual studio 2005
i'm trying to read the text on a drop down list but it always gives me the initial text and not the text that is selected by the user?
is this a bug or is there another way about it?
ive tried this

Expand|Select|Wrap|Line Numbers
  1. Dim A as string = dropdownlist1.selecteditem.text 'gives initial text
  2. Dim A as string = dropdownlist1.text                    'also gives initial text
  3.  
???
if you are binding your dropdownlist1 in page load, then place that code inside ->

if not ispostback then
YOUR CODE HERE
endif

Your problem may be because, everytime postback occurs, the controls get binded again. so, you will have to prevent the controls from being binded again when postback occurs.
Jun 21 '07 #4
maghi85
28
if you are binding your dropdownlist1 in page load, then place that code inside ->

if not ispostback then
YOUR CODE HERE
endif

Your problem may be because, everytime postback occurs, the controls get binded again. so, you will have to prevent the controls from being binded again when postback occurs.

how do you place the code inside?
Jun 22 '07 #5
gomzi
304 100+
how do you place the code inside?
What do you mean by that?
Jun 23 '07 #6
maghi85
28
What do you mean by that?
you wrote

if you are binding your dropdownlist1 in page load, then place that code inside ->

if not ispostback then
YOUR CODE HERE
endif

please explain
Jun 24 '07 #7
gomzi
304 100+
you wrote

if you are binding your dropdownlist1 in page load, then place that code inside ->

if not ispostback then
YOUR CODE HERE
endif

please explain
I explained earlier too maghi85.
Anyway....
Normally, what happens is that when a page loads, the contents in the page_load sub get executed.
i.e. in your case suppose you have placed the code for binding dropdownlist in the page_load area, then it gets binded with that data when the page is requested.
Now, later on when a postback occurs, i.e. either through a button or autopostback of your dropdownlist or whatever, the execution starts from the page load before it goes to the event for that respective control.
so, if you don't place your code inside "if not ispostback", then the dropdownlist(in your case) gets binded again with the data. And since it gets binded again, the default value also gets set again.
so, finally when you try to receive the selected value through the event for the control what you get is the default value that has been set again in the page load sub(in the absence of 'if not ispostback').
so, since you say that you are not getting the selected value through the event, the only problem which might be possible IMO is that you are binding the dropdownlist again.
so check it out!

wow!!! not written such a long explanation. am impressed!

Regards,
Gomzi.
Jun 24 '07 #8
Wing
28
An example of what Gomzi is trying to say without writing it for you

Code on default.aspx
Expand|Select|Wrap|Line Numbers
  1. <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
  2.             <asp:ListItem Value="1">Value 1</asp:ListItem>
  3.             <asp:ListItem Value="2">Value 2</asp:ListItem>
  4.             <asp:ListItem Value="3">Value 3</asp:ListItem>
  5. </asp:DropDownList
Code on default.aspx.vb
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         If Not IsPostBack Then
  3.             'Bind Data
  4.         End If
  5. End Sub
  6.  
  7. Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
  8.         Dim A As String = DropDownList1.SelectedItem.Text
  9.         Dim B As String = DropDownList1.SelectedValue
  10.         Response.Write(A & "<br>" & B)
  11. End Sub
Written to the browser when the index is changed.
Expand|Select|Wrap|Line Numbers
  1. Value 2
  2. 2  
Hope that helps you out more.
Jun 24 '07 #9
maghi85
28
thanks alot you guys
i haven't tried it yet
but im sure it'll work....
now I have a better understanding
Jun 25 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mantova | last post by:
Maybe it's simple, but I can't get it to work. I'm originally a webdeveloper, and just started to work on a C# windows application. I want a list, something similar to a <select><option> object,...
2
by: Big E | last post by:
I'm using ASP.Net and 1 Listbox and 1 ComboBox. When a user selects the contents in the listbox I want to populate the combobox with the text that he selected or double clicked. I've tried various...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
8
by: gv | last post by:
Ok, Hi all, new to asp.net. Simple question with web forms I have a Dropdownlist and a listbox, I want to click on and item in the dropdownlist and show items in listbox. that simple I...
10
by: Mr Newbie | last post by:
DropDown lists and Listboxes do not appear in the list of controls and values passed back to the server on PostBack in Request.Form object. Can someone confirm this to be correct and possibly...
1
by: Patrik Zdarsa | last post by:
Hi, I'm try VS 2005 and need UPDATE database record in viewform, all working when every filed is type TextBox (html INPUT) but I need change one TextBox to Listbox or dropdownlist and read data...
4
by: Jeff User | last post by:
Hi Using .NET 1.1, C#, web app I (actually our client) would like to be able to double click a selection in a listbox and have it postback to server . There I would want to access the item that...
1
by: murugavelmsc | last post by:
hi, in vs2005, i have a control of gridview and dropdown. in dropdown list have a item of table header which i configured in gridview. In Dropdown box, i selected one header means , it select the...
3
by: Mel | last post by:
On a tab I have one DropDownList which requires a postback and two ListBoxes which do not require any postback because I just have some javascript, defined in the aspx file, to copy items from one...
0
by: Mel | last post by:
On Oct 23, 8:30 am, bruce barker <nos...@nospam.comwrote: Huh? Did you mean Listbox not DropDownList? The drop-down is working fine, it's the Listbox data that gets cleared after the drop-down...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.