可以对绑定到自定义对象(CSV文件)的网格视图进行排序吗?

时间:2008-10-29 17:48:47

标签: asp.net

我有一个从CSV获取数据的Datagrid。没有文件按任何顺序排序,但我想按用户名(字段)排序gridview。怎么可以这样做?我的XML / gridview代码如下所示:

用于写入csv和填充gridview的Streamwriter:

    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 个答案:

答案 0 :(得分:1)

您可以使用ODBC驱动程序绑定到文本数据。一个例子是 http://www.thejackol.com/2004/07/01/connect-to-a-csv-file-using-odbc-c/

您可以使用数据适配器填充DataSet对象。绑定到数据集。你应该能够在那之后进行排序。