473,322 Members | 1,781 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,322 software developers and data experts.

Items showing up 2x in a listbox

I have some code where I populate some items in a listbox. The code is:
ListBoxDomesticExport.Items.Insert(0, "Domestic (Commercial)")
ListBoxDomesticExport.Items(0).Value = "0"

ListBoxDomesticExport.Items.Insert(1, "Domestic (All)")
ListBoxDomesticExport.Items(1).Value = "1"

ListBoxDomesticExport.Items.Insert(2, "Domestic (Non Commercial)")
ListBoxDomesticExport.Items(2).Value = "2"

ListBoxDomesticExport.Items.Insert(3, "Export")
ListBoxDomesticExport.Items(3).Value = "3"

ListBoxDomesticExport.Rows = 4
This works fine.
However, it populates the listbox 2 times, with the same data.

I only call the routine in 2 places. One is in the page_load event, below.

If Not Page.IsPostBack Then
setDomExport()
End If

The other is in a button click event, for a reset button.

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReset.Click
setDomExport()
End Sub
Basically, in both places, I set other listboxes I have on that same
page, and set some indexes to -1.

When I run the page though, the routine SetDomExport() gets run twice,
no matter what.

Why is this doing this? Is there a way to make it NOT run it twice, or
is there a way to keep it from adding the same elements to the listbox a
second time?

Any help appreciated.

BC
Oct 17 '06 #1
4 1210

If it were me, I'd recode the populate to this

private sub setDomExport
dim li as ListItem
li = new ListItem()
li.Text = Domestic (Commercial)"
li.Value = "0"
ListBoxDomesticExport.Items.Add(li)

li = new ListItem()
li.Text ="Domestic (All)"
li.Value = "1"
ListBoxDomesticExport.Items.Add(li)

''etc etc
end sub

That's just a "its more obvious" style thing......

Back to your question.

Can you do a

ListBoxDomesticExport.Clear() ''// or ListBoxDomesticExport.Items.Clear()
'' going from memory
when you call the reset button?

"Blasting Cap" <go****@christian.netwrote in message
news:e5**************@TK2MSFTNGP05.phx.gbl...
I have some code where I populate some items in a listbox. The code is:
ListBoxDomesticExport.Items.Insert(0, "Domestic (Commercial)")
ListBoxDomesticExport.Items(0).Value = "0"

ListBoxDomesticExport.Items.Insert(1, "Domestic (All)")
ListBoxDomesticExport.Items(1).Value = "1"

ListBoxDomesticExport.Items.Insert(2, "Domestic (Non
Commercial)")
ListBoxDomesticExport.Items(2).Value = "2"

ListBoxDomesticExport.Items.Insert(3, "Export")
ListBoxDomesticExport.Items(3).Value = "3"

ListBoxDomesticExport.Rows = 4
This works fine.
However, it populates the listbox 2 times, with the same data.

I only call the routine in 2 places. One is in the page_load event,
below.
>
If Not Page.IsPostBack Then
setDomExport()
End If

The other is in a button click event, for a reset button.

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReset.Click
setDomExport()
End Sub
Basically, in both places, I set other listboxes I have on that same
page, and set some indexes to -1.

When I run the page though, the routine SetDomExport() gets run twice,
no matter what.

Why is this doing this? Is there a way to make it NOT run it twice, or
is there a way to keep it from adding the same elements to the listbox a
second time?

Any help appreciated.

BC

Oct 17 '06 #2
"sloan" <sl***@ipass.netwrote in message
news:eV**************@TK2MSFTNGP02.phx.gbl...

If it were me, I'd recode the populate to this:

Private Sub setDomExport

ListBoxDomesticExport.Items.Clear()
ListBoxDomesticExport.Items.Add(new ListItem("Domestic (Commercial)", "0"))
ListBoxDomesticExport.Items.Add(new ListItem("Domestic (All)", "1"))
'etc

End Sub
Oct 17 '06 #3
and if it was me, i'd turn viewstate off, and call the loader from oninit.

-- bruce (sqwork.com)

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:eM**************@TK2MSFTNGP04.phx.gbl...
"sloan" <sl***@ipass.netwrote in message
news:eV**************@TK2MSFTNGP02.phx.gbl...

If it were me, I'd recode the populate to this:

Private Sub setDomExport

ListBoxDomesticExport.Items.Clear()
ListBoxDomesticExport.Items.Add(new ListItem("Domestic (Commercial)",
"0"))
ListBoxDomesticExport.Items.Add(new ListItem("Domestic (All)", "1"))
'etc

End Sub

Oct 17 '06 #4
I agree w/ Bruce. Are you sure it's firing that function twice? Is it
possible that the values were loaded from viewstate, then loaded again
by you? Either way, you should turn off the viewstate if you don't
need it.

Oct 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
3
by: Joey | last post by:
Hi, I'm trying to add a default item to my listbox but when I do it tells me that it's not defined, could someone tell me the syntax I need to use to get the listbox control to display a default...
4
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you...
4
by: John Wildes | last post by:
Hello I have a small program that I've created to generate accounting statements out of our policy managment system. The first part of the process is selecting the customer to create the...
11
by: Timo Kunze | last post by:
Hi! If you move the mouse over an item that's part of a treeview and wider than the treeview, a tooltip showing the full item text will be displayed. I try to do this for ListBoxes and...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
1
by: Ted | last post by:
Here is a stored procedure I created in MySQL: CREATE PROCEDURE `sp_find_food`( IN search_string varchar(255) ) BEGIN DECLARE ss VARCHAR(257); SET ss = CONCAT('%',search_string,'%'); SELECT...
2
by: koosh34 | last post by:
VS2005 VB.net 2.0 I have a form called options with a ListBox1 on it, to fill the list box from several events on the form I put the code to update the ListBox1 items into a sub in a separate code...
1
by: divya | last post by:
Hello, I used the below code to move selected items between two listboxes Left and Right:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPopup.aspx.cs" Inherits="TestPopup" %> ...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.