473,322 Members | 1,538 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.

DataGrid Question

In my application, I want to populate all the directories & files
existing in a directory on the server in a DataGrid. To ensure that
all the directories get listed first followed by all the files, I am
appending all the directories with 0 & all the files with 1.

Moreover, each directory & file listed in the DataGrid will have a
corresponding CheckBox. To differentiate between directories & files,
I am adding the string "*D" (without the quotes) to all the
directories & the string "*F" (again, without the quotes) to all the
files. I want to assign the corresponding CheckBoxes these IDs. For
e.g. if one of the directories is named "JOE", then the ID of the
CheckBox should be "chkJOE*D". Similarly, if there is a file named
"MyFile.txt", then its corresponding CheckBox should have the ID
"chkMyFile.txt*F".

There are 2 problems I am facing. First of all, I cannot display all
the directories & files in the DataGrid. Secondly, how do I ensure
that the ID of the CheckBoxes are assigned the string which I
mentioned above? This is the code:

<script runat="server">
Dim dInfo As DirectoryInfo

Sub Page_Load(.......)
dInfo = New DirectoryInfo(Server.MapPath("Directory1"))
Call ListFilesDirs(dInfo)
End Sub

Sub ListFilesDirs(ByVal dirInfo As DirectoryInfo)
Dim i As Integer
Dim iFind As Integer
Dim strURL As String
Dim strSize As String
Dim fInfo As FileInfo
Dim aList As ArrayList
Dim strListItem As String
Dim fsi As FileSystemInfo

aList = New ArrayList

For Each fsi In dirInfo.GetFileSystemInfos
If ((fsi.Attributes And FileAttributes.Directory) = 16)
Then
aList.Add("0" & fsi.Name & "<DIR>")
Else
fInfo = CType(fsi, FileInfo)
strSize = CStr(fInfo.Length)

If (strSize = 0) Then
strSize = "0.00"
End If

aList.Add("1" & fsi.Name & " - " & strSize & " MB - "
& fsi.CreationTime)
End If
Next
aList.Sort()

For i = 0 To aList.Count - 1
If (InStr(aList(i), "<DIR>") 0) Then
strListItem = Left(aList(i), Len(aList(i)) - 6)
strListItem = Mid(strListItem, 2,
Len(strListItem)) & "*D"
Else
strListItem = Left(aList(i), InStr(aList(i), " -
") - 1)
strListItem = Mid(strListItem, 2,
Len(strListItem)) & "*F"
End If

'Response.Write(Mid(aList(i), 2, Len(aList(i))) &
"<br>")
dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))
dgDomain.DataBind()
Next
End Sub
</script>

Note the commented Response.Write line just above the
dgDomain.DataSource line. When I uncomment this Response.Write line,
then all the directories & files get listed one after the other
correctly but they don't get populated in the DataGrid.

Note that the CheckBoxes should be displayed in the very first column
in the DataGrid. The Header of this first column should be a CheckBox
too so that checking/unchecking this Header CheckBox will check/
uncheck all the other CheckBoxes respectively.

Can someone please help me out with this?

Feb 19 '07 #1
5 2829
On Feb 19, 10:39 pm, r...@rediffmail.com wrote:
dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))
Note the commented Response.Write line just above the
dgDomain.DataSource line. When I uncomment this Response.Write line,
then all the directories & files get listed one after the other
correctly but they don't get populated in the DataGrid.
Sure, DataSource expected to be an array, and not a string.

Feb 19 '07 #2
On Feb 20, 4:07 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Feb 19, 10:39 pm, r...@rediffmail.com wrote:
dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))
Note the commented Response.Write line just above the
dgDomain.DataSource line. When I uncomment this Response.Write line,
then all the directories & files get listed one after the other
correctly but they don't get populated in the DataGrid.

Sure, DataSource expected to be an array, and not a string.
Sorry, Alexey, but I couldn't exactly get your point. Could you please
elaborate? A code sample will be really appreciated.

Thanks...

Feb 19 '07 #3
On Feb 20, 12:14 am, r...@rediffmail.com wrote:
On Feb 20, 4:07 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Feb 19, 10:39 pm, r...@rediffmail.com wrote:
dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))
Note the commented Response.Write line just above the
dgDomain.DataSource line. When I uncomment this Response.Write line,
then all the directories & files get listed one after the other
correctly but they don't get populated in the DataGrid.
Sure, DataSource expected to be an array, and not a string.

Sorry, Alexey, but I couldn't exactly get your point. Could you please
elaborate? A code sample will be really appreciated.

Thanks...
The following line

dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))

set a string as the DataSource of your grid.

I think that using

dgDomain.DataSource = aList

will work as you expected.

Feb 19 '07 #4
On Feb 20, 4:42 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Feb 20, 12:14 am, r...@rediffmail.com wrote:


On Feb 20, 4:07 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Feb 19, 10:39 pm, r...@rediffmail.com wrote:
dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))
Note the commented Response.Write line just above the
dgDomain.DataSource line. When I uncomment this Response.Write line,
then all the directories & files get listed one after the other
correctly but they don't get populated in the DataGrid.
Sure, DataSource expected to be an array, and not a string.
Sorry, Alexey, but I couldn't exactly get your point. Could you please
elaborate? A code sample will be really appreciated.
Thanks...

The following line

dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))

set a string as the DataSource of your grid.

I think that using

dgDomain.DataSource = aList

will work as you expected.- Hide quoted text -

- Show quoted text -
Thanks, Alexey; that has resolved the issued but I couldn't exactly
follow how does

dgDomain.DataSource = aList

resolve the issue & why doesn't

dgDomain.DataSource = aList(i)

populate the DataGrid? Could you please explain me this?

Moreover 2 new problems have also crept up. As you can see from the
code snippet I posted in the very first post in this thread, I am
appending all the directories with 0 & all the files with 1 so as to
ensure that all the directories get listed first followed by the files
but I would like to hide the 0's & 1's from the user. So if I just do

dgDomain.DataSource = aList

then the DataGrid displays all the directories preceded by 0 & all the
files preceded by 1. I can't use any String functions on aList since
it is an array & not a string. How do I get rid of the 0's & 1's from
the directories & files respectively when the DataGrid displays them?

The second problem is, as shown in the code snippet in post #1, if an
item happens to be a file, then I want to display the size along with
the creation time of the file in the DataGrid but I want to display
these 2 pieces of info in 2 different columns in the DataGrid. In
other words, the DataGrid should have 4 columns - the first column
must display a CheckBox for each item (which I have already taken care
of), the second column should display the directory/file name, the
third column should display the size of each item if that item happens
to be a file & the fourth column should display the date & time at
which the files/directories were created.

The Header of the first column in the DataGrid should be a CheckBox
(which I have already taken care of), the Header of the second column
should be 'NAME', the Header of the third column should be 'SIZE' &
the Header of the fourth column should be 'CREATION TIME'.

Now how do I make the DataGrid display the details in this manner?

Thanks once again for your helpful suggestions,

Regards,

Ron

Feb 20 '07 #5
On Feb 20, 5:24 am, r...@rediffmail.com wrote:

First of all, I found mysterious on the screen

For i = 0 To aList.Count - 1
.....
dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))
dgDomain.DataBind()
Next

By using this code you changed your data source (aList.Count - 1)
times.

This action

dgDomain.DataSource = ...
dgDomain.DataBind()

has to be without any loop!

>
dgDomain.DataSource = aList

resolve the issue & why doesn't

dgDomain.DataSource = aList(i)

populate the DataGrid? Could you please explain me this?
aList(i) does populate the grid. But you have to understand the
difference between an array/collection and an element of array.

In your case:

aList is a collection of many items - the set of directories and files
aList(i) is an item of this array, just one item - a file or directory

Assuming the first problem "First of all, I cannot display all the
directories & files in the DataGrid." is solved

then the DataGrid displays all the directories preceded by 0 & all the
files preceded by 1. I can't use any String functions on aList since
it is an array & not a string. How do I get rid of the 0's & 1's from
the directories & files respectively when the DataGrid displays them?
I think you always have at first the directories and then then files.

Isn't it?

The second problem is, as shown in the code snippet in post #1, if an
item happens to be a file, then I want to display the size along with
the creation time of the file in the DataGrid but I want to display
these 2 pieces of info in 2 different columns in the DataGrid. In
other words, the DataGrid should have 4 columns - the first column
If DataGrid should have 4 columns then the DataSource (in our case -
ArrayList) should have 4 "columns". The existing ArrayList cannot be
used as a multidimensional array directly and I don't know what *good*
solution I can suggest you here. If I were you perhaps I would go for
a another solution with custom class and so on, but because you have
already in-line code which is working (I assume), why do we making it
complicated with the DataGrid? Do not bind anything to grid, remove
that control from the page and generate your table in the loop

Response.Write "<table>"

For i = 0 To aList.Count - 1
.....
Next

Response.Write "</table>"

I think it will be better

Feb 20 '07 #6

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

Similar topics

2
by: magister | last post by:
Hello, I have xml like this.... <test> <question>sdfsa</question> <section><question>43ga</question> <question>asdf</question> </test>
0
by: Randy | last post by:
Hello, I have two questions... I have a datagrid. I'm capturing the cell via HitTestInfo. The first question is fairly simple. I'm using an example of how to capture the row/column I found on the...
3
by: BBFrost | last post by:
Ok, I know how to count the number of selected datagrid rows using the code below. What has me stumped is how to determine when the selected rows within a datagrid have been changed. The...
6
by: BBFrost | last post by:
I'm using Net 1.1 (2003) SP1 & Windows 2000 Here's the issue ... Rows 12 thru 24 are selected in a datagrid. The user now unselects rows 12 thru 24 and selects rows 45 thru 70 ??? How can...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
2
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last,...
3
by: Danky | last post by:
Hello Masters! Anyone can help me with the datagrid, well, the app load a lot of data from DB and it show on the datagrid, and well, I need to allow paging and.... the issue is with the event...
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.