I have a text file with data which might look something like:
UserName
Address
PostCode
PhoneNumber
The first four elements of the textfile belongs to one user, the next four to next user etc. I want to read from a textfile, and display data of each user. Reading and distinguishing data of each user is fine.
The problem is how would I display the data as such? I would like to display the data as a table or something along the line, where each user has a row. Say I want to display data like;
Name – Address – Postcode – PhoneNumber
Matt – 15 The – PO30 78 – 088997655
Mike – 16 The – PO31 78 – 088998955
If I was using a database I guess you can easily display it with a GridView, is there anyway to display it after reading from textfile?
Many Thanks,
Mike
EDIT:
I copied the code you gave, dragged a gridView to the page. Changed it’s ID to dataGridView1
DataTable table = new DataTable();
table.Columns.Add("UserName", typeof(string));
table.Columns.Add("Address", typeof(string));
table.Columns.Add("PostCode", typeof(string));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("LastName", typeof(string));
dataGridView1.DataSource = table;
table.Rows.Add(Label8.Text, Label4.Text, Label5.Text, Label6.Text, Label7.Text);
You can load your data into a DataTable and bind a gridview to the DataTable just as you would if it were coming from from a database. Something like this: