FileInfo not working in DataGrid

T

tshad

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
 
K

Karl Seguin [MVP]

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
 
T

tshad

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top