2012-06-30 51 views
-1
protected void ReadHtmlTable(string patientName, string startHour, string startMinute, int rowspan) 
      { 
       for(int i = 0; i <= tableAppointment.Rows.Count - 1; i++) 
        { 
         for(int j = 0; j <= tableAppointment.Rows[i].Cells.Count - 1; j++) 
         { 
          if(tableAppointment.Rows[i].Cells[j].InnerHtml.Trim() == startHour) 
          { 
           if(tableAppointment.Rows[i].Cells[j + 1].InnerHtml.Trim()== startMinute) 
           { 
            tableAppointment.Rows[i].Cells[j + 2].InnerText = patientName; 
            tableAppointment.Rows[i].Cells[j + 2].RowSpan = rowspan; 
            tableAppointment.Rows[i].Cells[j + 2].Style.Add("color", "green"); 
            tableAppointment.Rows[i].Cells[j + 2].Style.Add("background", "green"); 
           } 
          } 
         } 
        } 
     } 

上面的代碼是我的服務器端代碼,它在OnSaveStateComplete(EventArgs e)事件上執行。我正在閱讀我的HTML表格在C#中。當我檢查它的第一個單元格第二個單元格文本時,它的結果如下所示:「\ r \ n \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t「。我使用修剪結束,但不工作。cells.InnerHtml not getting correct way

+0

用InnerText.Trim()替換InnerHtml.Trim()。我想你在那裏有「
」而不是「\ r \ n」。 –

+0

\t \t \t \t \t \t \t \t \t 08:00 \t \t \t \t \t \t \t \t – John

+0

以上cheebum是我的TD – John

回答

0

試試這個

string str = "\r\n\t\t\t\t\t\t\t\t\t08:00\r\n\t\t\t\t\t\t\t\t".Trim('\t', '\r', '\n'); 
+0

沒有不工作........ – John

0

你應該能夠在MSDNRegEx.Replace(tableAppointment.Rows[i].Cells[j + 1].InnerHtml, "\\s+", "");

的Regex.Replace法正則表達式它的存在。那裏的例子也有處理空白。

+0

不工作的人 – John

+0

您是否追查過插入和結果是在推薦使用替換或修剪功能之前和之後?你有沒有對HTML表格的控制,最好不要在單元格內輸入如此多的標籤等。更多信息,我敢肯定,我們可以與你合作。 我們都假設\ r \ t等是換行符信息 - 實際上是用轉義序列返回的字符串,例如「\\ r \\ n \\ t」等或轉義序列。因爲這需要不同的方法(在這種情況下是模式)。 – matthewnreid

+0

哈哈你的投票我的問題如何不合理你是否 – John

相關問題