我是 asp 的初学者,在尝试进行一些表动态更新时,我遇到了一个奇怪的问题:
首先在页面加载时,我从 xml 文件中获取一些数据并将其添加到我的表中。这部分没有引起任何问题,数据显示在页面上。
第二部分是当我尝试将表的更新数据写回文件时,我得到一个空文件。在调试模式下查看值后,似乎当我获取 HtmlTable 实例并检查 Row 属性时,只有一行是标题行。
附上表格声明:
<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();
}
有谁知道为什么我无法检索我刚刚添加到表中的数据?
谢谢,
摩西