473,545 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Webform - Create SortedListbox Control - need help!

Hello,

I would like to create a sorted listbox which has one property that I can
set to true or false to show if the listbox should be sorted (I may
potentially
add another one for the sort direction - asc, or desc). Then, if it
should be sorted, everytime an item is added to the list via Items.Add or or
deleted via items.remove, I would like it to automatically resort the list.

I have created the base class below... but this only allows me to manually
run the public SORT method. I would prefer that this be a private sub, and
be
called automatically when items are added or deleted ( note: databound
lists would have to be sorted via the SQL used reading the database).

Can this be done? Can someone help me out with how?

Below I have the new class as I have it started now....

Thanks!

Jim

=============== =============== == Start of SortedListBox class
=============== =============== =============== ========

Public Class SortedListBox
Inherits System.Web.UI.W ebControls.List Box

Private _sorted As Boolean

Public Property Sorted() As Boolean
Get
Return _sorted
End Get
Set(ByVal Value As Boolean)
_sorted = Value
End Set
End Property

Public Sub Sort()
' Declare private variables needed to get the sort to work.
Dim x As New Collection
Dim Ar As New ArrayList
Dim li As ListItem
Dim txtString As String

' Add the text to a sortable object
For Each li In Items
Ar.Add(li.Text. ToString)
Next

' Sort the list of objects
Ar.Sort()

' Create a new list of items
For Each txtString In Ar
Dim templi As New ListItem
templi.Text = txtString
templi.Value = Items.FindByTex t(txtString).Va lue
x.Add(templi)
Next
' Clear all the items from the listbox
Items.Clear()
' Add back in the sorted items
For Each li In x
Items.Add(li)
Next
End Sub
End Class

Nov 20 '05 #1
9 1861
Cor
Hi James,

I don't know if I can help you, but for I can do that, I need something to
know.
How do you fill your listbox.
And how the deletes and the adds.

Cor
Nov 20 '05 #2
Cor
Hi Fergus,
First I thought (still is) this is typical yours, but then I thought lets
first try to get some information.
Maybe I can do it too. I forgot to set the subject again back.
Sorry
Cor
ps. when you think you can answer this, do it otherwise I do it tomorrow
morning (GMT) , I wrote this to overcome that there is a "go to ASP.NET" and
this has again nothing to with that but is deep 100% VB.net language.
Nov 20 '05 #3
Cor,

I simply do the listitem.add method, or listitem.delete method.

Think of it as a web page where you show two listboxes, one on the left with
all options for a user, and one on the right showing options selected for
the user (both of which we want sorted for ease of viewing - even as they
add/move from listbox to listbox). We let them move the items between the
two listboxes by using arrows in between them. Then, whenever they want
they can press the Apply button, which makes the changes permanent to the
database.

Does that help?

Jim

"Cor" <no*@non.com> wrote in message
news:3f******** **************@ reader21.wxs.nl ...
Hi James,

I don't know if I can help you, but for I can do that, I need something to
know.
How do you fill your listbox.
And how the deletes and the adds.

Cor

Nov 20 '05 #4
Hi James,

I think you can handle the Load event of your control to achieve this. When
you press the button to add an item to them listbox, IE posts back the page
to the server and the whole page is reloaded. This event fires every time
when your control is loaded. In the Load event, you can call your private
sub Sort() to sort the the items.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Reply-To: "James Radke" <jr*****@wi.rr. com>
| From: "James Radke" <jr*****@wi.rr. com>
| References: <uM************ **@TK2MSFTNGP12 .phx.gbl>
<3f************ **********@read er21.wxs.nl>
| Subject: Re: Create SortedListbox Control - need help! (Typical for
Fergus I think)
| Date: Tue, 23 Sep 2003 15:40:59 -0500
| Lines: 30
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#y************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: cpe-24-167-241-101.wi.rr.com 24.167.241.101
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:140716
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
|
| Cor,
|
| I simply do the listitem.add method, or listitem.delete method.
|
| Think of it as a web page where you show two listboxes, one on the left
with
| all options for a user, and one on the right showing options selected for
| the user (both of which we want sorted for ease of viewing - even as they
| add/move from listbox to listbox). We let them move the items between the
| two listboxes by using arrows in between them. Then, whenever they want
| they can press the Apply button, which makes the changes permanent to the
| database.
|
| Does that help?
|
| Jim
|
| "Cor" <no*@non.com> wrote in message
| news:3f******** **************@ reader21.wxs.nl ...
| > Hi James,
| >
| > I don't know if I can help you, but for I can do that, I need something
to
| > know.
| > How do you fill your listbox.
| > And how the deletes and the adds.
| >
| > Cor
| >
| >
|
|
|

Nov 20 '05 #5
Cor
Hi James,
I just started at your problem when I saw Kevin had given you an anwser.
What I will add to Kevins answer is,
The Load event on the serverside will be started when a webcontrol button or
a webcontrol with the attribute postback=true is clicked.
(Your from and too buttons)
When I was you, I would first test what that means on a real Internet
connection.
I can imaging that it takes a lot of traffic when the user does this kind of
operations on the serverside.
Or maybe Kevin knows that,
Cor
Nov 20 '05 #6
The only thing I am worried about in placing it in the load event, is that
it would also then happen if I happen to have the control databound, right?
Is there a way I can identify if it is databound, and if so, NOT do the
sort?

And, would the LOAD occurr before, or after the item.add/item.delete in a
postback event?

Jim

"Cor" <no*@non.com> wrote in message
news:3f******** *************** @reader22.wxs.n l...
Hi James,
I just started at your problem when I saw Kevin had given you an anwser.
What I will add to Kevins answer is,
The Load event on the serverside will be started when a webcontrol button or a webcontrol with the attribute postback=true is clicked.
(Your from and too buttons)
When I was you, I would first test what that means on a real Internet
connection.
I can imaging that it takes a lot of traffic when the user does this kind of operations on the serverside.
Or maybe Kevin knows that,
Cor

Nov 20 '05 #7
Hi James,

You're right. The Load will occurr before the button_click event fires.
Apologize for my mistake.

Since the ListBox doesn't have an event which fires when the item.add() is
called, I recommend you to use composition instead of inherit. That is the
ListBox is a member of your user control. In the add() method of your own
control, call ListBox.Items.A dd() first, and then call your Sort() method.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Reply-To: "James Radke" <jr*****@wi.rr. com>
| From: "James Radke" <jr*****@wi.rr. com>
| References: <uM************ **@TK2MSFTNGP12 .phx.gbl>
<3f************ **********@read er21.wxs.nl>
<#y************ **@TK2MSFTNGP10 .phx.gbl>
<hb************ **@cpmsftngxa06 .phx.gbl>
<3f************ ***********@rea der22.wxs.nl>
| Subject: Re: Create SortedListbox Control - need help! (Typical for
Fergus I think)
| Date: Wed, 24 Sep 2003 11:21:11 -0500
| Lines: 30
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <u7************ *@tk2msftngp13. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: cpe-24-167-241-101.wi.rr.com 24.167.241.101
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:140948
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
|
| The only thing I am worried about in placing it in the load event, is that
| it would also then happen if I happen to have the control databound,
right?
| Is there a way I can identify if it is databound, and if so, NOT do the
| sort?
|
| And, would the LOAD occurr before, or after the item.add/item.delete in a
| postback event?
|
| Jim
|
| "Cor" <no*@non.com> wrote in message
| news:3f******** *************** @reader22.wxs.n l...
| > Hi James,
| > I just started at your problem when I saw Kevin had given you an anwser.
| > What I will add to Kevins answer is,
| > The Load event on the serverside will be started when a webcontrol
button
| or
| > a webcontrol with the attribute postback=true is clicked.
| > (Your from and too buttons)
| > When I was you, I would first test what that means on a real Internet
| > connection.
| > I can imaging that it takes a lot of traffic when the user does this
kind
| of
| > operations on the serverside.
| > Or maybe Kevin knows that,
| > Cor
| >
| >
|
|
|

Nov 20 '05 #8
Cor
Hi James,

I was thinking that the meaning of your code was a model for something as
Public function (byvalue as listbox) as listbox
And then in the load of the page (or every other place before the page is
sended back)
xs as new sortedlistbox
listboxa = xs.sort(listbox a)

But now I think I see it wrong?

Cor

ps. I don't know if this works, I did not test it.
Nov 20 '05 #9
Kevin,

So, would I still create a class which 'inherits' from the listbox? I
guess I don't understand what you mean by 'composition', do you have a small
example? Would that still make all the methods/properties of the listbox
available through it?

Thanks!

Jim

"Kevin Yu" <v-****@online.mic rosoft.com> wrote in message
news:h%******** ********@cpmsft ngxa06.phx.gbl. ..
Hi James,

You're right. The Load will occurr before the button_click event fires.
Apologize for my mistake.

Since the ListBox doesn't have an event which fires when the item.add() is
called, I recommend you to use composition instead of inherit. That is the
ListBox is a member of your user control. In the add() method of your own
control, call ListBox.Items.A dd() first, and then call your Sort() method.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Reply-To: "James Radke" <jr*****@wi.rr. com>
| From: "James Radke" <jr*****@wi.rr. com>
| References: <uM************ **@TK2MSFTNGP12 .phx.gbl>
<3f************ **********@read er21.wxs.nl>
<#y************ **@TK2MSFTNGP10 .phx.gbl>
<hb************ **@cpmsftngxa06 .phx.gbl>
<3f************ ***********@rea der22.wxs.nl>
| Subject: Re: Create SortedListbox Control - need help! (Typical for
Fergus I think)
| Date: Wed, 24 Sep 2003 11:21:11 -0500
| Lines: 30
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <u7************ *@tk2msftngp13. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: cpe-24-167-241-101.wi.rr.com 24.167.241.101
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:140948
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
|
| The only thing I am worried about in placing it in the load event, is that | it would also then happen if I happen to have the control databound,
right?
| Is there a way I can identify if it is databound, and if so, NOT do the
| sort?
|
| And, would the LOAD occurr before, or after the item.add/item.delete in a | postback event?
|
| Jim
|
| "Cor" <no*@non.com> wrote in message
| news:3f******** *************** @reader22.wxs.n l...
| > Hi James,
| > I just started at your problem when I saw Kevin had given you an anwser. | > What I will add to Kevins answer is,
| > The Load event on the serverside will be started when a webcontrol
button
| or
| > a webcontrol with the attribute postback=true is clicked.
| > (Your from and too buttons)
| > When I was you, I would first test what that means on a real Internet
| > connection.
| > I can imaging that it takes a lot of traffic when the user does this
kind
| of
| > operations on the serverside.
| > Or maybe Kevin knows that,
| > Cor
| >
| >
|
|
|

Nov 20 '05 #10

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

Similar topics

2
2260
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to help with the navigation through a datagrid. The control handles all the paging issues and on the webform I do all the DataBinding. My problem...
4
2314
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to help with the navigation through a datagrid. The control handles all the paging issues and on the webform I do all the DataBinding. My problem...
3
3270
by: trint | last post by:
Ok, I have tried to do this with the System.Web.UI and can't find anything for the webform. It seems much easier for a Winform. Any help in trapping Webform keydown event and keyup event is appreciated. Thanks, Trint
1
1413
by: Melson | last post by:
Hi Can anyone give me suggestion. I've 10 tables in MS SQL. Each table has primary key and different fields in each table. I need to create ASPNET webform to add and update each table. What I'm thinking is to create 1 webform for each table. So the project will have 10 webform to add and edit each table. I don't think this is a good design....
2
8376
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the...
9
12884
by: Peter Afonin | last post by:
Hello: I need to clear all textboxes on the webform after the data has been submitted. How can I do this in one step? I found a C# code: // get a reference to your form control Control frm = FindControl("YourFormID"); foreach(Control ctrl in frm.Controls)
3
22840
by: EJ1003 | last post by:
Hello I would like to create Activex Control uisng C# and use it in ASP.Net webform. User Control is not solving my requirement so I am going for Activex Control. Please guide me on this, how to do it, if any sample is provided will be of great help Thanks EJ
3
1592
by: Nuno | last post by:
How can I instantiate a webform2 object from webfrom1 codebehind? The class does not popup in intellisense and gives me and error if i try to create it. Nuno
5
2548
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have start web form and when the user clicks a button (server.transfer) they are directed to the second webform. I was wondering if there is a way to create an instance of the first webform on the second webform? I have a base webform class that both webforms inherit webform1 : BaseWebclass webform2 :BaseWebclass so I do not think I...
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7771
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.