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

FileInfo not working in DataGrid

I am having a problem with my Datagrid that displays my Files via GetFiles()

If I use a HyperLinkColumn - I can use the column name "Name" which is what
the result from GetFiles().

************************************************** ******
Sub GetFileList()
Dim dirInfo as DirectoryInfo = new
DirectoryInfo(Server.MapPath("/uploads/"))

articleList.DataSource = dirInfo.GetFiles("*.txt")
articleList.DataBind()
End Sub
************************************************** ************

I added a LinkButton as I am having a problem with the HyperLinkColumn but
for some reason I am getting an error that says:

No default member found for type 'FileInfo'.

I am using the following LinkButton definition in my DataGrid:

<asp:LinkButton ID="DocumantName" Text='<%# Container.DataItem("Name")%>'
OnClick="SetName_Click" runat="server"/>

Am I not setting my Text attribute correctly? "Name" works for the
HyperLinkColumn, why not for the LinkButton?

Here is the whole DataGrid:
************************************************** ****
<asp:datagrid id="articleList"
AutoGenerateColumns="False"
Font-Name="Verdana"
DataKeyField="FullName"
OnItemDataBound="articleList_ItemDataBound"
OnDeleteCommand="articleList_DeleteFile"
OnItemCommand="ItemCmd"
Width="500px" style="padding-left:2px;border-collapse:separate"
runat="server" >
<alternatingitemstyle BackColor="#FFFFFF"/>
<itemstyle BackColor="#E9E9E9" ForeColor="#0000FF"/>
<headerstyle CssClass="jay" BackColor="#000000" ForeColor="#FFFFFF"
Font-Bold="true" />
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name"
DataTextField="Name" HeaderText="File Name"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write
Time" DataFormatString="{0:d}">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Length" HeaderText="File Size"
DataFormatString="{0:#,##0 bytes}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="DownLoad">
<ItemTemplate>
<asp:LinkButton id="DownLoad" Text="DownLoad" CommandName="Show"
Runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="DocumantName" Text='<%#
Container.DataItem("Name")%>' OnClick="SetName_Click" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
************************************************** *********

Thanks,

Tom
Nov 6 '06 #1
2 1653
Have you tried using:
<%# DataBinder.Eval(Container.DataItem, "Name") %>

or, if you're in 2.0, just:

<%# Eval("Name") %>

or...

<%# ctype(Container.DataItem, FileInfo).Name %>

Karl
--
http://www.openmymind.net/
http://www.codebetter.com/
"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I am having a problem with my Datagrid that displays my Files via
GetFiles()

If I use a HyperLinkColumn - I can use the column name "Name" which is
what the result from GetFiles().

************************************************** ******
Sub GetFileList()
Dim dirInfo as DirectoryInfo = new
DirectoryInfo(Server.MapPath("/uploads/"))

articleList.DataSource = dirInfo.GetFiles("*.txt")
articleList.DataBind()
End Sub
************************************************** ************

I added a LinkButton as I am having a problem with the HyperLinkColumn but
for some reason I am getting an error that says:

No default member found for type 'FileInfo'.

I am using the following LinkButton definition in my DataGrid:

<asp:LinkButton ID="DocumantName" Text='<%# Container.DataItem("Name")%>'
OnClick="SetName_Click" runat="server"/>

Am I not setting my Text attribute correctly? "Name" works for the
HyperLinkColumn, why not for the LinkButton?

Here is the whole DataGrid:
************************************************** ****
<asp:datagrid id="articleList"
AutoGenerateColumns="False"
Font-Name="Verdana"
DataKeyField="FullName"
OnItemDataBound="articleList_ItemDataBound"
OnDeleteCommand="articleList_DeleteFile"
OnItemCommand="ItemCmd"
Width="500px" style="padding-left:2px;border-collapse:separate"
runat="server" >
<alternatingitemstyle BackColor="#FFFFFF"/>
<itemstyle BackColor="#E9E9E9" ForeColor="#0000FF"/>
<headerstyle CssClass="jay" BackColor="#000000" ForeColor="#FFFFFF"
Font-Bold="true" />
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name"
DataTextField="Name" HeaderText="File Name"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write
Time" DataFormatString="{0:d}">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Length" HeaderText="File Size"
DataFormatString="{0:#,##0 bytes}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="DownLoad">
<ItemTemplate>
<asp:LinkButton id="DownLoad" Text="DownLoad" CommandName="Show"
Runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="DocumantName" Text='<%#
Container.DataItem("Name")%>' OnClick="SetName_Click" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
************************************************** *********

Thanks,

Tom


Nov 7 '06 #2
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:uU**************@TK2MSFTNGP04.phx.gbl...
Have you tried using:
<%# DataBinder.Eval(Container.DataItem, "Name") %>
Yes, and it works. Why don't I have to do the same in the HyperLinkColumn?

I also have to do the same thing with HyperLink as I do with LinkButton (as
you suggested).

Thanks,

Tom
>
or, if you're in 2.0, just:

<%# Eval("Name") %>

or...

<%# ctype(Container.DataItem, FileInfo).Name %>

Karl
--
http://www.openmymind.net/
http://www.codebetter.com/
"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>I am having a problem with my Datagrid that displays my Files via
GetFiles()

If I use a HyperLinkColumn - I can use the column name "Name" which is
what the result from GetFiles().

************************************************* *******
Sub GetFileList()
Dim dirInfo as DirectoryInfo = new
DirectoryInfo(Server.MapPath("/uploads/"))

articleList.DataSource = dirInfo.GetFiles("*.txt")
articleList.DataBind()
End Sub
************************************************* *************

I added a LinkButton as I am having a problem with the HyperLinkColumn
but for some reason I am getting an error that says:

No default member found for type 'FileInfo'.

I am using the following LinkButton definition in my DataGrid:

<asp:LinkButton ID="DocumantName" Text='<%# Container.DataItem("Name")%>'
OnClick="SetName_Click" runat="server"/>

Am I not setting my Text attribute correctly? "Name" works for the
HyperLinkColumn, why not for the LinkButton?

Here is the whole DataGrid:
************************************************* *****
<asp:datagrid id="articleList"
AutoGenerateColumns="False"
Font-Name="Verdana"
DataKeyField="FullName"
OnItemDataBound="articleList_ItemDataBound"
OnDeleteCommand="articleList_DeleteFile"
OnItemCommand="ItemCmd"
Width="500px" style="padding-left:2px;border-collapse:separate"
runat="server" >
<alternatingitemstyle BackColor="#FFFFFF"/>
<itemstyle BackColor="#E9E9E9" ForeColor="#0000FF"/>
<headerstyle CssClass="jay" BackColor="#000000"
ForeColor="#FFFFFF" Font-Bold="true" />
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name"
DataTextField="Name" HeaderText="File Name"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write
Time" DataFormatString="{0:d}">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Length" HeaderText="File Size"
DataFormatString="{0:#,##0 bytes}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="DownLoad">
<ItemTemplate>
<asp:LinkButton id="DownLoad" Text="DownLoad"
CommandName="Show" Runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="DocumantName" Text='<%#
Container.DataItem("Name")%>' OnClick="SetName_Click" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
************************************************* **********

Thanks,

Tom



Nov 7 '06 #3

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

Similar topics

2
by: John Bowman | last post by:
Hi All, ..NET 1.1... I'm wondering if there is any approach more convenient to get a list of FileInfo objects than the following. For example, if I wanted to get 1 list of all the Exe's and all...
0
by: Craig Douglas | last post by:
Hello, does anyone have a good way of ordering a FileInfo collection in order that I can present it in a datagrid, or alternatively sort it within the datagrid? Thanks Craig
1
by: Antonio | last post by:
Good morning, I've the following file system : C: -> HTML -> Aziende -> Azienda_1 -> a.jpg -> Azienda_2 -> a.jpg ... -> Azienda_N -> a.jpg my desire is to create an array of fileinfo...
0
by: Sosh | last post by:
Hi, Can someone tell me how to bind a FileInfo to a DataGrid. At the moment I am using something along the lines of someDataGrid.DataSource = someFileInfo; But am getting...
5
by: Lance | last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user...
1
by: Benjamin | last post by:
I am trying to make a file I created a hidden file. I think I need to use the setfileattribute() but I cannot find it anywhere. I found this on msdn:...
1
by: Tim Failes | last post by:
This seems a trival question, but I cannot get it to work properly... Essentially my question is, how can I create a text file, and guarantee it is given the current date/time as the Creation Time?...
3
by: rn5a | last post by:
To work with files, when should one use the File class & when should one use the FileInfo class? Similarly, to work with directories, when should one use the Directory class & when should one...
5
by: Tom P. | last post by:
I am having the following problem: I create a FileSystemWatcher and wait for events. When the event does happen I refresh a FileSystemInfo list and set properties accordingly (IsFile, IsDir,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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,...

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.