2012-06-30 49 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

相关问题