473,698 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(S erver.MapPath(" Directory1"))
Call ListFilesDirs(d Info)
End Sub

Sub ListFilesDirs(B yVal 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.GetFile SystemInfos
If ((fsi.Attribute s And FileAttributes. Directory) = 16)
Then
aList.Add("0" & fsi.Name & "<DIR>")
Else
fInfo = CType(fsi, FileInfo)
strSize = CStr(fInfo.Leng th)

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

aList.Add("1" & fsi.Name & " - " & strSize & " MB - "
& fsi.CreationTim e)
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.DataSo urce = Mid(aList(i), 2, Len(aList(i)))
dgDomain.DataBi nd()
Next
End Sub
</script>

Note the commented Response.Write line just above the
dgDomain.DataSo urce 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 2899
On Feb 19, 10:39 pm, r...@rediffmail .com wrote:
dgDomain.DataSo urce = Mid(aList(i), 2, Len(aList(i)))
Note the commented Response.Write line just above the
dgDomain.DataSo urce 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.DataSo urce = Mid(aList(i), 2, Len(aList(i)))
Note the commented Response.Write line just above the
dgDomain.DataSo urce 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.DataSo urce = Mid(aList(i), 2, Len(aList(i)))
Note the commented Response.Write line just above the
dgDomain.DataSo urce 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.DataSo urce = Mid(aList(i), 2, Len(aList(i)))

set a string as the DataSource of your grid.

I think that using

dgDomain.DataSo urce = 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.DataSo urce = Mid(aList(i), 2, Len(aList(i)))
Note the commented Response.Write line just above the
dgDomain.DataSo urce 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.DataSo urce = Mid(aList(i), 2, Len(aList(i)))

set a string as the DataSource of your grid.

I think that using

dgDomain.DataSo urce = 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.DataSo urce = aList

resolve the issue & why doesn't

dgDomain.DataSo urce = 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.DataSo urce = 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.DataSo urce = Mid(aList(i), 2, Len(aList(i)))
dgDomain.DataBi nd()
Next

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

This action

dgDomain.DataSo urce = ...
dgDomain.DataBi nd()

has to be without any loop!

>
dgDomain.DataSo urce = aList

resolve the issue & why doesn't

dgDomain.DataSo urce = 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 multidimensiona l 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
3264
by: magister | last post by:
Hello, I have xml like this.... <test> <question>sdfsa</question> <section><question>43ga</question> <question>asdf</question> </test>
0
1076
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 net. It uses System.Windows.Forms.DataGrid.HitTestInfo myHitTest; The first question is, when I use this in my code, it compiles and works fine. But when I type... System.Windows.Forms.DataGrid and press the "." at the end of DataGrid, I don't...
3
4435
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 DataGrid object doesn't seem to have a any type of a selection changed type of event I can grab. THE QUESTION: Does anyone know how to determine when the selected row or set of rows within a datagrid has changed ??? This is driving me nuts !
6
1715
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 I tell that the user has reselected a different set of rows in a datagrid.
2
4327
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 how to use this code? please help! http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20862953.html
2
17018
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 the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
2
2331
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, Fax, Phone, Category). Put an Edit column at the end... Now what?! If you go into Edit mode -- you can only edit 5 cells -- not all the rest of the Record's fields...not enough!
3
1574
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 PageIndexChanged of the datagrid 'coz every time when the user change of page the app load again all data and another processes with the data even though I have load one dataset with the data for the datagrid..... the question is? What can I do to...
4
2284
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 combobox in a datagrid? Any other suggestions/articles on how to implement many-many relations in the frontend (which of course are 2 one-many relations)?
13
2487
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 them. In a plain vanilla DataGrid, when you click on the RowHeader, the appropriate row changes colors. I ASSUME this should be done in the Paint (or PaintText) override of the DataGridColumnStyle in question. My problem is that I don't know...
0
8685
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
8612
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
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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
7743
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
6532
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...
1
3053
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
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.