在GridView中显示进度条的问题

AILEENHHM 2012-06-25 09:56:11
想在GridView中显示进度条,进度数据存在绑定的xml中,如果按如下代码
<asp:TemplateField HeaderText="完成进度">
<ItemTemplate>
<img src='Image/progress.bmp' width='<%# 进度 %>'
height="10px" alt='<%# 进度 + "%" %>'>
</ItemTemplate>
</asp:TemplateField>
怎么从xml中得到进度值,然后能显示在上面代码中?或者有别的更好的办法在 GridView中显示进度?
谢谢了~~~~
...全文
533 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kgd256 2012-12-10
  • 打赏
  • 举报
回复
引用 2 楼 Yujiexiaoyu 的回复:
引用 1 楼 的回复:学学 xmlDatasource控件,或者更加通用的 objectDatasource控件。 这是基本入门知识,任何书上都有。懒得说什么。 对你这句话,我也懒得说什么。
别人已经告诉你用什么方法可以了,难道还要一行一行代码打给你啊
孟子E章 2012-06-26
  • 打赏
  • 举报
回复
绑定XML采用
<%#XPath("XML节点")%>

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


ASPX 代码
<%@ 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.XmlNode)Container.DataItem).Attributes["value"].Value %></td><td><%#XPath("@text")%></td></tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>

xml 文件格式如下:
XML 代码

<?xml version="1.0" encoding="utf-8"?>
<Cities>
<City text="北京" value="bj">
<District value="haidian" text="海淀区"></District>
<District value="changping" text="昌平区"></District>
<District value="chaoyang" text="朝阳区"></District>
<District value="pinggu" text="平谷区"></District>
</City>
<City text="上海" value="sh">
<District value="pudong" text="浦东区"></District>
<District value="xuhui" text="徐汇区"></District>
</City>
<City text="郑州" value="zz">
<District value="erqi" text="二七区"></District>
<District value="huiji" text="惠济区"></District>
<District value="jinshui" text="金水区"></District>
</City>
</Cities>

孟子E章 2012-06-26
  • 打赏
  • 举报
回复
使用 GridView 显示进度图片和进度文字的例子

<%@ Page Language="C#" EnableViewState="false" %>

<!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)
{
if (!Page.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;

//测试用显示字段
dt.Columns.Add(new System.Data.DataColumn("1月", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("2月", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("3月", typeof(System.String)));
//测试用进度数据
String[] x = { "10%", "20%", "50%", "80%", "90%", "100%" };
Random r = new Random();
for (int i = 0; i < 8; i++)
{
dr = dt.NewRow();
dr[0] = x[r.Next(0, x.Length)];
dr[1] = x[r.Next(0, x.Length)];
dr[2] = x[r.Next(0, x.Length)];
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>使用 GridView 显示进度图片和进度文字的例子</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="1月">
<ItemTemplate>
<div style="position: relative; width: 200px;"><img alt="" src="http://livedocs.adobe.com/flex/3_cn/langref/images/createGradientBox-2.jpg" width="<%#Eval("1月") %>" height="20" /><br />
<div style="width: 200px; position: absolute; z-index: 100; top: 0px; text-align: center;"><%#Eval("1月")%></div>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="2月">
<ItemTemplate>
<div style="position: relative; width: 200px;"><img alt="" src="http://livedocs.adobe.com/flex/3_cn/langref/images/createGradientBox-2.jpg" width="<%#Eval("2月") %>" height="20" /><br />
<div style="width: 200px; position: absolute; z-index: 100; top: 0px; text-align: center;"><%#Eval("2月")%></div>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="3月">
<ItemTemplate>
<div style="position: relative; width: 200px;"><img alt="" src="http://livedocs.adobe.com/flex/3_cn/langref/images/createGradientBox-2.jpg" width="<%#Eval("3月") %>" height="20" /><br />
<div style="width: 200px; position: absolute; z-index: 100; top: 0px; text-align: center;"><%#Eval("3月")%></div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
Yujiexiaoyu 2012-06-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

学学 xmlDatasource控件,或者更加通用的 objectDatasource控件。

这是基本入门知识,任何书上都有。懒得说什么。
[/Quote]



对你这句话,我也懒得说什么。
  • 打赏
  • 举报
回复
学学 xmlDatasource控件,或者更加通用的 objectDatasource控件。

这是基本入门知识,任何书上都有。懒得说什么。

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧