DataTable dtGridView = new DataTable();
            ViewState.Add("TempList", dtGridView);
            dtGridView.Columns.Add("SourceWareHouse", typeof(string));
            dtGridView.Columns.Add("DestWareHouse", typeof(string));
            dtGridView.Columns.Add("Others", typeof(string));            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strSourceWareHourse = dt.Rows[i][1].ToString();
                string strDestWareHourse = dt.Rows[i][2].ToString();
                string strCostsIds = dt.Rows[i][3].ToString();
                string[] ary = strCostsIds.Split('|');
                int intCostsUnitPriceTable = Convert.ToInt32(ary[0]);
                int CostsUnitPriceId = Convert.ToInt32(ary[1]);                DataTable dtt = (DataTable)ViewState["TempList"];
                DataRow  dtGridViewRC =dtt.Rows;
                object[] rowVals = new Object[3];
                rowVals[0] = strSourceWareHourse;
                rowVals[1] = strDestWareHourse;                if (intCostsUnitPriceTable == 1)
                {
                    DataTable dt1 = price1Table.GetPrice1ByCostsUnitPriceId(CostsUnitPriceId);
                    string strOthers = "起运地:" + dt1.Rows[i]["FromCityAreaName"].ToString() + "\\n" +
                    "到达地:" + dt1.Rows[i]["ToCityAreaName"].ToString() + "\\n" ";
                    rowVals[2] = strOthers;
                }
                else if (intCostsUnitPriceTable == 2)
                {           
                 }
                dtGridViewRC.Add(rowVals);
                ViewState["TempList"] = dtt;            }
            GridView1.DataSource = dtGridView;
            GridView1.DataBind();

解决方案 »

  1.   

    跟一下代码,OR try catch一下
      

  2.   

    DataTable dtGridView = new DataTable();
                dtGridView.Columns.Add("SourceWareHouse", typeof(string));
                dtGridView.Columns.Add("DestWareHouse", typeof(string));
                dtGridView.Columns.Add("Others", typeof(string));            for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string strSourceWareHourse = dt.Rows[i][1].ToString();
                    string strDestWareHourse = dt.Rows[i][2].ToString();
                    string strCostsIds = dt.Rows[i][3].ToString();
                    string[] ary = strCostsIds.Split('|');
                    int intCostsUnitPriceTable = Convert.ToInt32(ary[0]);
                    int CostsUnitPriceId = Convert.ToInt32(ary[1]);                DataRow  dtGridViewRC =dtGridView.NewRow();
                    dtGridViewRC[0] = strSourceWareHourse;
                    dtGridViewRC[1] = strDestWareHourse;                if (intCostsUnitPriceTable == 1)
                    {
                        DataTable dt1 = price1Table.GetPrice1ByCostsUnitPriceId(CostsUnitPriceId);
                        string strOthers = "起运地:" + dt1.Rows[i]["FromCityAreaName"].ToString() + "\\n" +
                        "到达地:" + dt1.Rows[i]["ToCityAreaName"].ToString() + "\\n" ";
                        dtGridViewRC[2] = strOthers;
                    }
                    else if (intCostsUnitPriceTable == 2)
                    {           
                    }
                    dtGridView.Rows.Add(dtGridViewRC);
                }
                GridView1.DataSource = dtGridView;
                GridView1.DataBind();