日期:2014-05-17  浏览次数:20543 次

在GridView中显示进度条的问题
想在GridView中显示进度条,进度数据存在绑定的xml中,如果按如下代码
  <asp:TemplateField HeaderText="完成进度"> 
  <ItemTemplate> 
  <img src='Image/progress.bmp' width='<%# 进度 %>' 
  height="10px" alt='<%# 进度 + "%" %>'>
  </ItemTemplate> 
  </asp:TemplateField>  
怎么从xml中得到进度值,然后能显示在上面代码中?或者有别的更好的办法在 GridView中显示进度?
谢谢了~~~~

------解决方案--------------------
绑定XML采用
<%#XPath("XML节点")%>

以 XML 文件为数据源进行嵌套绑定


ASPX 代码
HTML code
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  protected void Page_Load(object sender, EventArgs e)
  {
    XmlDataSource xds = new XmlDataSource();
    xds.DataFile = "~/2.xml";
    xds.ID = "XmlDataSource1";
    form1.Controls.Add(xds);
    Repeater1.DataSourceID =  Repeater3.DataSourceID = "XmlDataSource1";
    Repeater1.DataBind();
    Repeater3.DataBind();
  }

  protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
      System.Xml.XPath.XPathNavigator nav = ((System.Xml.XPath.IXPathNavigable)e.Item.DataItem).CreateNavigator();
      System.Xml.XPath.XPathNodeIterator it = nav.Select("./District");
      Repeater Repeater2 = e.Item.FindControl("Repeater2") as Repeater;
      Repeater2.DataSource = it;
      Repeater2.DataBind();
    }
  }
  protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {      
      IEnumerable em = XPathBinder.Select(e.Item.DataItem, "District") as IEnumerable;
      em.GetEnumerator();
      Repeater Repeater4 = e.Item.FindControl("Repeater4") as Repeater;
      Repeater4.DataSource = em;
      Repeater4.DataBind();
    }
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
  <form id="form1" runat="server">
   <h1>方法1</h1>
  <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
    <ItemTemplate>
      <h2 style="background: #ede">
        <%#XPath("@text")%></h2>
      <asp:Repeater ID="Repeater2" runat="server">
      <HeaderTemplate><table border="1"></HeaderTemplate><FooterTemplate></table></FooterTemplate>
        <ItemTemplate>
          <tr><td><%#XPath("@value")%></td><td><%#XPath("@text")%></td></tr>
        </ItemTemplate>
      </asp:Repeater>
    </ItemTemplate>
  </asp:Repeater>
  <h1>方法2</h1>
  <asp:Repeater ID="Repeater3" runat="server" OnItemDataBound="Repeater3_ItemDataBound">
    <ItemTemplate>
      <h2 style="background: #ede">
        <%#XPath("@text")%></h2>
      <asp:Repeater ID="Repeater4" runat="server">
      <HeaderTemplate><table border="1"></HeaderTemplate><FooterTemplate></table></FooterTemplate>
        <ItemTemplate>
          <tr><td><%#((System.Xml