Protected void button#click (Object sender, eventargs E)
{
String filename = This. fileupload1.filename. Trim ();
This. gridview1.datasource = loaddata (filename );
This. gridview1.databind ();
}
Public datatable loaddata (string filename)
{
Datatable dt = new datatable ();
DT. Columns. Add ("Lucky Draw user", typeof (string ));
DT. Columns. Add ("Lottery time", typeof (string ));
DT. Columns. Add ("win?", typeof (string ));
DT. Columns. Add ("remaining lottery Times", typeof (string ));
String Path = server. mappath (filename );
Fileupload1.saveas (PATH );
Streamreader reader = new streamreader (path, system. Text. encoding. Default); // open the file and read the text into the stream. // use the default system encoding.
This. label1.text = reader. readtoend ();
This. label1.visible = false;
String [] arrstr = This. label1.text. Split (New char [] {'/R','/N'}); // put the total number of rows in the array
String [] cells;
For (INT I = 1; I <arrstr. length; I ++)
{
Cells = arrstr [I]. tostring (). Split ('/t'); // truncates each field in a row
For (Int J = 0; j <cells. length; j ++)
{
Datarow rows = DT. newrow ();
Rows ["lottery user"] = cells [0];
Rows ["Lottery time"] = cells [1];
Rows ["win?"] = cells [2];
Rows ["remaining lottery times"] = cells [3];
DT. Rows. Add (rows );
}
}
Reader. Close ();
Return DT;
}