我是asp的啓動者,同時試圖做一些表動態更新,我陷入了一個奇怪的問題:
第一次在頁面加載我從一些數據XML文件並將其添加到我的表。這部分沒有引起任何問題,數據顯示在頁面上。
第二部分是當我嘗試將表格的更新數據寫回文件時,我找回了一個空文件。在調試模式下查看值後,似乎當我得到HtmlTable實例並檢查Row屬性時,只有一行是標題行。無法從asp.net中更新的HtmlTable對象中獲取數據
連接的表聲明:
<table id="users" class="ui-widget ui-widget-content" runat="server">
<thead>
<tr class="ui-widget-header ">
<th>Title</th>
<th>Link From Ibms</th>
<th>Dismiss</th>
</tr>
</thead>
</table>
和閱讀並在服務器上寫功能:
private void readLinkXml()
{
if (!File.Exists(path)) // no file.
return;
XmlTextReader reader = new XmlTextReader(path);
reader.WhitespaceHandling = WhitespaceHandling.None;
// reader.Read();
while (!reader.EOF) // load loop
{
if ((reader.Name == "ChannelMap" && !reader.IsStartElement()))
{
break;
}
while ((reader.Name != "links" || !reader.IsStartElement()))
reader.Read(); // advance to next <links> tag
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell title = new HtmlTableCell();
title.InnerHtml = reader.GetAttribute("TITLE"); // get link title.
row.Cells.Add(title);
HtmlTableCell link = new HtmlTableCell();
link.InnerHtml = reader.GetAttribute("VOD_URL"); // get link url.
row.Cells.Add(link);
HtmlTableCell buttonCell = new HtmlTableCell();
buttonCell.Attributes.Add("id", "table_button");
row.Cells.Add(buttonCell);
users.Rows.Add(row); // add xml asset as row in link table.
reader.Read(); // and now either at <links> tag or </ChannelMap
}
reader.Close();
}
private void writeLinksXml()
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineChars = "\r\n";
settings.NewLineHandling = NewLineHandling.Replace;
XmlWriter writer = XmlWriter.Create(path, settings);
writer.WriteStartDocument();
writer.WriteStartElement("ChannelMap");
bool first = true;
foreach (HtmlTableRow row in users.Rows)
{
if (first)
{
first = false;
continue;
}
writer.WriteStartElement("links");
writer.WriteAttributeString("TITLE", row.Cells[0].InnerText);
writer.WriteAttributeString("VOD_URL", row.Cells[1].InnerText);
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
沒有人知道爲什麼我不能夠找回我剛添加到數據表?
感謝,
摩西
沒人知道這裏可能是什麼問題? – moshe