2012-04-07 39 views
0

我有一个数据集读入XML WebResponse,然后我从这个数据集中提取和合并表格如何添加7个硬编码标签到合并表中显示在数据网格中,标签始终是相同的值,并且顺序将始终相同。最简单的方法来标记数据网格中的行

我想让它容易我想添加7行标题到表?用数据网格显示。

我试过

WebRequest req = WebRequest.Create(m_uri); 
     WebResponse rsp; 
     req.Method = "POST"; 
     req.ContentType = "text/xml"; 
     StreamWriter writer = new StreamWriter(req.GetRequestStream()); 
     writer.WriteLine(buildXml().ToString()); 
     writer.Close(); 
     rsp = req.GetResponse(); 

     //Get the Posted Data 
     StreamReader reader = new StreamReader(rsp.GetResponseStream()); 
     string rawXml = reader.ReadToEnd(); 
     XmlDocument xml = new XmlDocument(); 
     xml.LoadXml(rawXml); 

     //Use XPath to Navigate the Document 
     int status = Convert.ToInt32(xml.SelectSingleNode(@"/RatingServiceSelectionResponse/Response/ResponseStatusCode").InnerText); 
     if (status == 1) 
     { 




      StringReader srxml = new StringReader(rawXml); 

      DataSet dsAuthors = new DataSet("RatedShipment"); 
      dsAuthors.ReadXml(srxml); 

      dsAuthors.EnforceConstraints = false; 

      DataTable Shipment = dsAuthors.Tables[2]; 
      DataTable TotalCharges = dsAuthors.Tables[8]; 
      DataTable table = new DataTable("UPS Service"); 

      Shipment.Merge(TotalCharges); 
      Shipment.Columns.Remove("RatedShipmentWarning"); 
      Shipment.Columns.Remove("CurrencyCode"); 
      Shipment.Rows.RemoveAt(7); 
      DataColumn UPSService = new DataColumn(); 
      UPSService.DataType = typeof(string); 
      UPSService.ColumnName = "UPS Service"; 
      Shipment.Columns.Add(UPSService); 
      Shipment.Rows[0].Cells[0].Value = "UPS Ground"; 
      Shipment.Rows[1].Cells[0].Value = "UPS Three Day"; 
      Shipment.Rows[2].Cells[0].Value = "UPS Second Day A.M."; 
      Shipment.Rows[3].Cells[0].Value = "UPS Second Day"; 
      Shipment.Rows[6].Cells[0].Value = "UPS Next Day Air Saver"; 
      Shipment.Rows[4].Cells[0].Value = "UPS Next Day Air Early A.M."; 
      Shipment.Rows[5].Cells[0].Value = "UPS Next Day Air"; 



     dataGridView1.DataSource = Shipment; 


     } 
     else 
     { 
      MessageBox.Show("Unable To Process: Please Check All Fields Are Entered"); 
     } 

但这些细胞中的行之后是不正确的。

+0

您的应用程序是asp.net或Windows的窗体应用程序? – 2012-04-07 21:48:53

+0

用于行标题的窗体应用程序 – 2012-04-07 21:53:07

回答

0

然后,你必须这样做:

foreach (DataGridViewRow row in datagrid.Rows) { 
    row.Cells(0).Value = "yourtext"; 
} 
+0

?从上到下? – 2012-04-07 22:03:07

+0

你的意思是你需要重新命名网格的标题?你正在谈论哪些标题? – 2012-04-07 22:04:28

+0

我需要每行中的第一个单元格作为特定的行1行2行3行4从上到下解释每行是什么。 – 2012-04-07 22:09:04

相关问题