我读取了文本文件的内容放到DataGridView中,文本文件中的内容以逗号搁开,而现在需要将一个字符串中的内容分为三部分读取后放到DataGridView中,最后在把三个部分合并为一个字符串,如何解决这样的问题,请各位高手帮忙,最好有相关的代码,谢谢大家了

解决方案 »

  1.   

    string [] infos = info.Splite(',');一般你用DataView是用来绑定控件的对吧?直接指定DataSource = infos就可以了亚
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
        {
            this.GridView1.DataSource = file_get_contents(@"c:\1.txt");
            this.GridView1.DataBind();
        }
        private DataTable file_get_contents(string path)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("f1");
            dt.Columns.Add("f2");
            dt.Columns.Add("f3");        using (StreamReader sr = new StreamReader(path, System.Text.Encoding.GetEncoding("GB2312")))
            {
                string line;
                DataRow dr;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] a = line.Split(',');
                    dr = dt.NewRow();
                    dr["f1"] = a[0];
                    dr["f2"] = a[1];
                    dr["f3"] = a[2];
                    dt.Rows.Add(dr);
                }
            }
            return dt;
        }
      

  3.   

    把用分割符隔开的文本数据加载到DataTable的三个列,然后使用Ado.net中的表达式来组合显示他们的连接。
    http://www.microsoft.com/china/MSDN/library/data/dataAccess/ADONETEXP.mspx