Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello sir,

I have multiple textfiles in a folder. I want to bind these all files to gridview. how to do this task.

Please any body suggest me.

Thanking you.
Posted
Updated 6-Mar-11 4:00am
v2
Comments
Henry Minute 6-Mar-11 10:00am    
Do you want to bind the file names, location etc., or the contents of the files?
sathish.jampala 7-Mar-11 0:04am    
tanks for ur reply.
i have a folder contained multiple textfiles. i want to read those files and bind to gridview. i write following code

string[] files = Directory.GetFiles("E:\\DOTNET APPLICATIONS\\Asp.net\\TextfilestoGrid\\TextFolder\\");
foreach (string file in files)
{
Stream msgStream = File.Open(file, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(msgStream);
string str = sr.ReadToEnd();
//ArrayList al = new ArrayList();

DataTable dt = new DataTable();
dt.Columns.Add("TextFiles");
DataRow dr = dt.NewRow();
dr["TextFiles"] = str;
dt.Rows.Add(dr);
sr.Close();
msgStream.Close();

GV.DataSource = dt;
GV.DataBind();

when ever i debug the application, all files are coming to stream object but they are not binded to gridview. output is displaying only one columnname that is "TextFiles" with no data.
plz help me;
thanking you.

1 solution

If it's the file contents you wish to bind to, I can think of two approaches:

Create a master file and copy the contents of the other files into that. Bind the GridView to the master file.

Create a DataSet with DataTables. Each DataTable can be filled from a seperate text file. Then you can manipulate the tables...create relations or use the Merge() function to combine DataTables or manually copy rows and cells. Then you can Bind to the resultant DataTable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900