tags:

views:

202

answers:

2

Hi,

I have a Datagrid which is getting its data from CSV. No file is sorted in any order, but I want to order the gridview by Username (a field). How could this be done? My XML/gridview code looks like the following:

Streamwriter for writing to csv and populating gridview:

    string filename = @"D:\www\isolated\LocalUser\cc-suppressions\generatedsuppressions\surpressions.csv";
    StreamWriter sWriter = new StreamWriter(Server.MapPath("Surpression.csv"));
    string Str = string.Empty;
    string headertext = "";
    sWriter.WriteLine(headertext);
    int cellLimit = GridView3.Rows[1].Cells.Count;
    for (int i = 0; i <= (this.GridView3.Rows.Count - 1); i++)
    {
        for (int j = 0; j <= (this.GridView3.Rows[i].Cells.Count - 1); j++)
        {
            Str = this.GridView3.Rows[i].Cells[j].Text.ToString();
            if (Str == "&nbsp;")
                Str = "";
            Str = (Str + ",");
            sWriter.Write(Str);
        }

        sWriter.WriteLine();
    }
    sWriter.Close();
    sWriter.Dispose();
}
this.GridView3.DataBind();
+1  A: 

You can use the ODBC driver to bind to text data. An example is http://www.thejackol.com/2004/07/01/connect-to-a-csv-file-using-odbc-c/

You can use a data adapter to populate a DataSet object. Bind to the dataset. You should be able to sort after that.

Matt Brunell
A: 

Thanks. I will give that a try!

dotnetdev