473,712 Members | 2,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alter Values in ListBox

A ListBox lists all the files & directories existing in a directory on
the server. If an item in the ListBox happens to be a directory, then
the name of the directory is appended with the text [DIR]. Similarly,
if an item in the ListBox happens to be a file, then the name of the
file is appended with the text [FILE]. Assuming that the ListBox lists
2 directories & 3 files, this is how the ListBox would look like:

MyDir1 [DIR]
MyDir2 [DIR]
File1.aspx [FILE]
File2.aspx [FILE]
File3.aspx [FILE]

Since I want the ListBox to add additional information of each
directory & file, I am adding the items to the ListBox using the Add
method & not using the DataSource property to bind the directories &
files to the ListBox:

Sub Page_Load(..... )
Dim fsi As FileSystemInfo
Dim dInfo As DirectoryInfo

dInfo = New DirectoryInfo(S erver.MapPath(" Folder1"))

For Each fsi In dInfo.GetFileSy stemInfos
If ((fsi.Attribute s And FileAttributes. Directory) = 16) Then
lstFD.Items.Add (fsi.Name & " [DIR]")
Else
lstFD.Items.Add (fsi.Name & " [FILE]")
End If
Next
End Sub

When I have s look at the source of the ListBox, I find that the value
assigned to each item in the ListBox is exactly the same as the text of
the item like this:

<select id="lstFD">
<option value="MyDir1 [DIR]">MyDir1 [DIR]</option>
<option value="MyDir2 [DIR]">MyDir2 [DIR]</option>
<option value="File1.as px [FILE]">File1.asp x [FILE]</option>
<option value="File2.as px [FILE]">File2.asp x [FILE]</option>
<option value="File3.as px [FILE]">File3.asp x [FILE]</option>
</select>

As is evident above, the value of each item & its corresponding text is
exactly the same.

I want to remove the text [DIR] & [FILE] appended to each directory &
file respectively ONLY from the value of each item so that the value of
each item gets set to just the directory or the file name i.e. the
source of the ListBox should be

<select id="lstFD">
<option value="MyDir1"> MyDir1 [DIR]</option>
<option value="MyDir2"> MyDir2 [DIR]</option>
<option value="File1.as px">File1.asp x [FILE]</option>
<option value="File2.as px">File2.asp x [FILE]</option>
<option value="File3.as px">File3.asp x [FILE]</option>
</select>

How do I accomplish this?

I tried adding the following code immediately after For....Next loop
starts (i.e. just before the If condition)

lstFD.DataValue Field = fsi.Name

but that doesn't make any difference. The value of each item still
remains exactly the same as its corresponding text.

Jan 8 '07 #1
2 1796
ADDENDUM:
--------

Strangely, if I add the following line:

Response.Write( lstFD.DataValue Field & "<br>")

anywhere within the For...Next loop but outside the If...Else condition
like this:

For Each fsi In dInfo.GetFileSy stemInfos
lstFD.DataValue Field = fsi.Name
If ((fsi.Attribute s And FileAttributes. Directory) = 16) Then
lstFD.Items.Add (fsi.Name & " [DIR]")
Else
lstFD.Items.Add (fsi.Name & " [FILE]")
End If
Response.Write( lstFD.DataValue Field & "<br>")
Next

then the Response.Write line doesn't spit out the text [DIR] & [FILE]
for each directory & file respectively; it just spits out the directory
name & the file name respectively but the value of each item (when the
source is viewed) still appends the text [DIR] & {FILE] along with the
directory name & file name respectively.

rn**@rediffmail .com wrote:
A ListBox lists all the files & directories existing in a directory on
the server. If an item in the ListBox happens to be a directory, then
the name of the directory is appended with the text [DIR]. Similarly,
if an item in the ListBox happens to be a file, then the name of the
file is appended with the text [FILE]. Assuming that the ListBox lists
2 directories & 3 files, this is how the ListBox would look like:

MyDir1 [DIR]
MyDir2 [DIR]
File1.aspx [FILE]
File2.aspx [FILE]
File3.aspx [FILE]

Since I want the ListBox to add additional information of each
directory & file, I am adding the items to the ListBox using the Add
method & not using the DataSource property to bind the directories &
files to the ListBox:

Sub Page_Load(..... )
Dim fsi As FileSystemInfo
Dim dInfo As DirectoryInfo

dInfo = New DirectoryInfo(S erver.MapPath(" Folder1"))

For Each fsi In dInfo.GetFileSy stemInfos
If ((fsi.Attribute s And FileAttributes. Directory) = 16) Then
lstFD.Items.Add (fsi.Name & " [DIR]")
Else
lstFD.Items.Add (fsi.Name & " [FILE]")
End If
Next
End Sub

When I have s look at the source of the ListBox, I find that the value
assigned to each item in the ListBox is exactly the same as the text of
the item like this:

<select id="lstFD">
<option value="MyDir1 [DIR]">MyDir1 [DIR]</option>
<option value="MyDir2 [DIR]">MyDir2 [DIR]</option>
<option value="File1.as px [FILE]">File1.asp x [FILE]</option>
<option value="File2.as px [FILE]">File2.asp x [FILE]</option>
<option value="File3.as px [FILE]">File3.asp x [FILE]</option>
</select>

As is evident above, the value of each item & its corresponding text is
exactly the same.

I want to remove the text [DIR] & [FILE] appended to each directory &
file respectively ONLY from the value of each item so that the value of
each item gets set to just the directory or the file name i.e. the
source of the ListBox should be

<select id="lstFD">
<option value="MyDir1"> MyDir1 [DIR]</option>
<option value="MyDir2"> MyDir2 [DIR]</option>
<option value="File1.as px">File1.asp x [FILE]</option>
<option value="File2.as px">File2.asp x [FILE]</option>
<option value="File3.as px">File3.asp x [FILE]</option>
</select>

How do I accomplish this?

I tried adding the following code immediately after For....Next loop
starts (i.e. just before the If condition)

lstFD.DataValue Field = fsi.Name

but that doesn't make any difference. The value of each item still
remains exactly the same as its corresponding text.
Jan 8 '07 #2
OK....friends I got the solution to specify a different value for each
item in the ListBox. This is how it can be done (for those who might
come across a similar problem in the future):

Dim fsi As FileSystemInfo
Dim dInfo As DirectoryInfo

dInfo = New DirectoryInfo(S erver.MapPath(" Folder1"))

For Each fsi In dInfo.GetFileSy stemInfos
If ((fsi.Attribute s And FileAttributes. Directory) = 16) Then
lstFD.Items.Add (New ListItem(fsi.Na me & " [DIR]", fsi.Name))
Else
lstFD.Items.Add (New ListItem(fsi.Na me & " [FILE]", fsi.Name))
End If
Next
rn**@rediffmail .com wrote:
ADDENDUM:
--------

Strangely, if I add the following line:

Response.Write( lstFD.DataValue Field & "<br>")

anywhere within the For...Next loop but outside the If...Else condition
like this:

For Each fsi In dInfo.GetFileSy stemInfos
lstFD.DataValue Field = fsi.Name
If ((fsi.Attribute s And FileAttributes. Directory) = 16) Then
lstFD.Items.Add (fsi.Name & " [DIR]")
Else
lstFD.Items.Add (fsi.Name & " [FILE]")
End If
Response.Write( lstFD.DataValue Field & "<br>")
Next

then the Response.Write line doesn't spit out the text [DIR] & [FILE]
for each directory & file respectively; it just spits out the directory
name & the file name respectively but the value of each item (when the
source is viewed) still appends the text [DIR] & {FILE] along with the
directory name & file name respectively.

rn**@rediffmail .com wrote:
A ListBox lists all the files & directories existing in a directory on
the server. If an item in the ListBox happens to be a directory, then
the name of the directory is appended with the text [DIR]. Similarly,
if an item in the ListBox happens to be a file, then the name of the
file is appended with the text [FILE]. Assuming that the ListBox lists
2 directories & 3 files, this is how the ListBox would look like:

MyDir1 [DIR]
MyDir2 [DIR]
File1.aspx [FILE]
File2.aspx [FILE]
File3.aspx [FILE]

Since I want the ListBox to add additional information of each
directory & file, I am adding the items to the ListBox using the Add
method & not using the DataSource property to bind the directories &
files to the ListBox:

Sub Page_Load(..... )
Dim fsi As FileSystemInfo
Dim dInfo As DirectoryInfo

dInfo = New DirectoryInfo(S erver.MapPath(" Folder1"))

For Each fsi In dInfo.GetFileSy stemInfos
If ((fsi.Attribute s And FileAttributes. Directory) = 16) Then
lstFD.Items.Add (fsi.Name & " [DIR]")
Else
lstFD.Items.Add (fsi.Name & " [FILE]")
End If
Next
End Sub

When I have s look at the source of the ListBox, I find that the value
assigned to each item in the ListBox is exactly the same as the text of
the item like this:

<select id="lstFD">
<option value="MyDir1 [DIR]">MyDir1 [DIR]</option>
<option value="MyDir2 [DIR]">MyDir2 [DIR]</option>
<option value="File1.as px [FILE]">File1.asp x [FILE]</option>
<option value="File2.as px [FILE]">File2.asp x [FILE]</option>
<option value="File3.as px [FILE]">File3.asp x [FILE]</option>
</select>

As is evident above, the value of each item & its corresponding text is
exactly the same.

I want to remove the text [DIR] & [FILE] appended to each directory &
file respectively ONLY from the value of each item so that the value of
each item gets set to just the directory or the file name i.e. the
source of the ListBox should be

<select id="lstFD">
<option value="MyDir1"> MyDir1 [DIR]</option>
<option value="MyDir2"> MyDir2 [DIR]</option>
<option value="File1.as px">File1.asp x [FILE]</option>
<option value="File2.as px">File2.asp x [FILE]</option>
<option value="File3.as px">File3.asp x [FILE]</option>
</select>

How do I accomplish this?

I tried adding the following code immediately after For....Next loop
starts (i.e. just before the If condition)

lstFD.DataValue Field = fsi.Name

but that doesn't make any difference. The value of each item still
remains exactly the same as its corresponding text.
Jan 8 '07 #3

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

Similar topics

7
2576
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need a little more help on one more point. This is what i've got. I have code that hunts for updated appointments in a public folder based on the order that happens to be open (code fires on an on open event) This works fine and updates my
6
5216
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I have also tried changing the second ListBox to an HtmlSelect control) using bog standard JavaScript code like so where "used" is the name of my <select> control: used.options = new Option(name, typeId); This all works fine and I can move across...
6
2653
by: Niggy | last post by:
Hi there, I would like to display the values of the index as chosen by the user in a listbox. These values would be as per the datavaluefield. On testing I get a value of -1: Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Me.Label1.Text = ListBox1.Items.Item(2).Text End Sub
0
1686
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing the listbox with no luck and, because it is already bound, I can't just delete the item directly from the listbox without an error (because it already has a datasource, you are not allowed to delete/add anything to the listbox directly). The...
7
4090
by: technocraze | last post by:
Hi guys, I encountered this error while using the AfterUpdate event for my listbox. Error: Update or CancelUpdate without using AddNew or Edit. What i wanted to achieve is just to display the selected values from the listbox into the textboxes. I have bounded both my listbox and textbox to the controlSource of the field of my table. I have two combo boxes. One is getting the from the query and other is matching the corresponding values...
1
2499
by: Intrepid_Yellow | last post by:
Hi, I have the following code that runs my report generator. The user selects a table from a combo box, then whatever fields they want from a list box. (This part all works and the report runs fine). There is then a combo box they can select a field from (eg CompanyID etc) and then the list box below that contains the values (eg Microsoft, Novell etc). These are all multi-select list boxes. Now I can get the code to work if the user...
11
4099
by: raylopez99 | last post by:
Keep in mind this is my first compiled SQL program Stored Procedure (SP), copied from a book by Frasier Visual C++.NET in Visual Studio 2005 (Chap12). So far, so theory, except for one bug (feature?) below. At some point I'm sure I'll be able to laugh about this, akin to forgeting a semi-colon in C/C++, but right now it's frustrating (time to sleep on it for a while). Problem-- For some reason I get the error when trying to save files...
1
2021
by: melvincwmah | last post by:
I have a form in which I would link the form fields to tables in the SQL database. Right now, I want to put in a listbox that will show three columns from a table called IssueAudit. The conditions for my listbox are: 1. The three columns (dubbed as Change History) are taken from IssueAudit under conditions that the ChangedFields value is 'CATE' - category. 2. The SAF-NO, a FK is the same key as the SAF_NO primary key in SAF
3
3762
by: Renilkumar | last post by:
Hi, I am using .net 2.0. I have a .aspx page with vb.net as codebehind. My form has one dropdown, 2 listboxes with add & remove button. During pageload I am loading all the values from the db to dropdown and after pageload, If I select value from the dropdown will load the data into the first listbox. I can select 1 or multiple values in the listbox and click on Add button will copy the data from source listbox to destination. Now how do...
0
8794
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8699
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9005
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7935
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6617
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5942
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4457
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4713
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2099
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.