List<CSVLine> list = new List<CSVLine>();
TextReader reader = new StreamReader(@"C:\MyFile.csv");
while (reader.Peek() > -1)
list.Add(new CSVLine(reader.ReadLine());
reader.Close();
grid.DataSource = list;
grid.DataBind();
public class CSVLine // use a better name if you want..
{
private string _v1;
private string _v2;
private string _v3;
// if there are more columns in the csv tab separated line, then you need to more ValueX members (like Value4, Value5)
// actually instead of using Value1, etc, you can use the actual business name like (Name, Age, etc)
public string Value1
{
get { return _v1; }
set { _v1 = value; }
}
public string Value2
{
get { return _v2; }
set { _v2 = value; }
}
public string Value3
{
get { return _v3; }
set { _v3 = value; }
}
public CSVLine(string csvLine)
{
string[] vals = csvLine.Split('\t');
Value1 = vals[0];
Value2 = vals[1];
Value3 = vals[2];
}
}
|