Reading a specific file and binding the data of that file to the gridview

Sandhyab
Posted by Sandhyab under ASP.NET category on | Points: 40 | Views : 912
Aspx:
 <asp:GridView ID="GridView1" runat="server">
</asp:GridView>

CodeBehind:
    protected void Page_Load(object sender, EventArgs e)
{

IList<Data> list = new List<Data>();
string path = @"D:\TestData.trx";
using (StreamReader sr = new StreamReader(path))
{
string line;
string[] row;
while ((line = sr.ReadLine()) != null)
{
row = line.Split(',');
if (row[0] == "#data")
{
Data obj = new Data();

obj.ColumnA = row[1];
obj.ColumnB = row[2];
obj.ColumnC = row[3];
list.Add(obj);
}
}
}
GridView1.DataSource = list;
GridView1.DataBind();


}


In class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Data
{
public string ColumnA { get; set; }
public string ColumnB { get; set; }
public string ColumnC { get; set; }

}

TestData.trx is .trx file that I have taken. It conatins the data with comma seperated.

Thanks & Regards

Comments or Responses

Login to post response