I have a GridView called 'Table' I want it to have 3 Columns. Column 1 is a Hyperlink Column and Column's 2 and 3 are just text. I have a for loop in my code behind.
I would like to know how to build a GridView table in code behind. If this is possible with specifiying the column types and adding data.
Regards
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education
Just to make it easier and to show what I'm attempting to do. I have the following code that reads the file in from a Directory. I then want to list them in a table with their File Name as a Hyperlink. I want to do this using a GridView or something like
it.
Dim di As New IO.DirectoryInfo("G:\VS2010 Projects\FileExplorer VB\FileExplorer VB\Users\Systep")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
'list the names of all files in the specified directory'
Try
For Each dra In diar1
Next
Catch ex As Exception
ErrorMsg.Text = ex.Message
End Try
I have a GridView called 'files' which I want to populate with the files that are in the directory. Does anyone have any ideas or pointers as to how would be the best way to go about doing this? I am looking into all post and answers so if I find something
in the mean time I will post my solution here.
So eveyone know what I'm finaly aiming for I'll explain below:
I work in a Secondary School and we need away for our students to browse their Home Directory in a Web Browser. We have looked into WebDav but have decided that we would raver they would have a Web Browser interface that will allow them to uplaod and download
files from our Servers.
Regards
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education
These are good ideas but I can't use the fill command to populate a table as the following error the following error;
Fill is not a member os System.IO.FileInfo
This is what I'm attempting to get.
File Name
File Sixe
Document.docx
204K
Accounts.xlsx
1255K
With Hyperlinks where the document names are. This is what I'm attempting to do. I'm using Directory and FileInfo from the System.IO namespace I want to display them in a table with Hyperlinks, bot of the above ways haven't helped so far with this issue.
I have now included my full code on the bottom of this post.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' make a reference to a directory'
Dim di As New IO.DirectoryInfo("G:\VS2010 Projects\FileExplorer VB\FileExplorer VB\Users\Systep")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
'list the names of all files in the specified directory'
Try
For Each dra In diar1
Next
Catch ex As Exception
ErrorMsg.Text = ex.Message
End Try
End Sub
End Class
Regards
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education
tparky
Member
112 Points
130 Posts
GridView add Populate from code behind
Apr 18, 2012 07:49 AM|LINK
Hi Guys,
I have a GridView called 'Table' I want it to have 3 Columns. Column 1 is a Hyperlink Column and Column's 2 and 3 are just text. I have a for loop in my code behind.
I would like to know how to build a GridView table in code behind. If this is possible with specifiying the column types and adding data.
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education
ramiramilu
All-Star
97899 Points
14509 Posts
Re: GridView add Populate from code behind
Apr 18, 2012 07:56 AM|LINK
use TemplateFields - http://msdn.microsoft.com/en-us/library/aa479353.aspx
Thanks,
JumpStart
tparky
Member
112 Points
130 Posts
Re: GridView add Populate from code behind
Apr 18, 2012 11:17 AM|LINK
Hi Guys,
Just to make it easier and to show what I'm attempting to do. I have the following code that reads the file in from a Directory. I then want to list them in a table with their File Name as a Hyperlink. I want to do this using a GridView or something like it.
Dim di As New IO.DirectoryInfo("G:\VS2010 Projects\FileExplorer VB\FileExplorer VB\Users\Systep") Dim diar1 As IO.FileInfo() = di.GetFiles() Dim dra As IO.FileInfo 'list the names of all files in the specified directory' Try For Each dra In diar1 Next Catch ex As Exception ErrorMsg.Text = ex.Message End TryI have a GridView called 'files' which I want to populate with the files that are in the directory. Does anyone have any ideas or pointers as to how would be the best way to go about doing this? I am looking into all post and answers so if I find something in the mean time I will post my solution here.
So eveyone know what I'm finaly aiming for I'll explain below:
I work in a Secondary School and we need away for our students to browse their Home Directory in a Web Browser. We have looked into WebDav but have decided that we would raver they would have a Web Browser interface that will allow them to uplaod and download files from our Servers.
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: GridView add Populate from code behind
Apr 18, 2012 11:25 AM|LINK
Refer
http://www.aspsnippets.com/Articles/Add-record-to-Database-using-ASP.Net-GridView-EmptyDataTemplate-and-FooterTemplate.aspx
Contact me
tparky
Member
112 Points
130 Posts
Re: GridView add Populate from code behind
Apr 19, 2012 09:19 AM|LINK
Hi Guys,
These are good ideas but I can't use the fill command to populate a table as the following error the following error;
Fill is not a member os System.IO.FileInfo
This is what I'm attempting to get.
With Hyperlinks where the document names are. This is what I'm attempting to do. I'm using Directory and FileInfo from the System.IO namespace I want to display them in a table with Hyperlinks, bot of the above ways haven't helped so far with this issue.
I have now included my full code on the bottom of this post.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' make a reference to a directory' Dim di As New IO.DirectoryInfo("G:\VS2010 Projects\FileExplorer VB\FileExplorer VB\Users\Systep") Dim diar1 As IO.FileInfo() = di.GetFiles() Dim dra As IO.FileInfo 'list the names of all files in the specified directory' Try For Each dra In diar1 Next Catch ex As Exception ErrorMsg.Text = ex.Message End Try End Sub End ClassThomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education
coolpal9
Member
164 Points
538 Posts
Re: GridView add Populate from code behind
Apr 19, 2012 09:41 AM|LINK
Pl refer to this link:
http://forums.asp.net/t/1794573.aspx/1?How+to+bind+SQL+statements+in+gridview
This might help you
tparky
Member
112 Points
130 Posts
Re: GridView add Populate from code behind
Apr 19, 2012 10:19 AM|LINK
Ok I have now tried the above examples and I get the following error.
Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource
Any ideas on how to fix this. I'm not using SQL or a Database of any type. The files are comming directly from the file system on a Server.
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education