如何在运行时动态分发xap文件
在我的应用程序中,我从某个信息中心下载一些 xml 数据文件,将包含图像的列添加到此 xml 文件(在 aspx.cs 中),然后将所有内容一起传递到 aspx 文件中的 GridView。
我想对 xap 文件做同样的事情 - 我需要根据数据上下文将它们添加到 GridView 中,但不幸的是有一个问题 - 对象没有像图像这样的 object.Attributes 。
这是我添加图像的代码(gvCurrency 是一个 GridView):
for (int i = 0; i < currency.Count; i++)
{
Image image = new Image();
image.Attributes.Add("src", "Images/Currency/" + xdoc.GetElementsByTagName("CURRENCYCODE")[i].InnerText + ".gif");
image.Attributes.Add("height", "15px");
image.Attributes.Add("width", "21px");
gvCurrency.Rows[i].Cells[0].Controls.Add(image);
}
我认为另一种可能性是将链接绑定到 aspx 文件中相应的 xap 文件,在这种情况下应该看起来像这样(如果我没记错的话) :
<asp:GridView ID="gvCurrency" runat="server" AutoGenerateColumns="False" ...>
<Columns>
<asp:BoundField DataField="FLAG" />
<asp:BoundField HeaderText="Currency Name" DataField="NAME" />
...
<asp:TemplateField >
<ItemTemplate>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="10px" height="10px">
<param name="source" value="ClientBin/ArrowTriangle.xap"/>
...
</div>
</ItemTemplate>
</asp:TemplateField >
</Columns>
</asp:GridView>
所以,我的问题是:如何在运行时动态分发 xap 文件(在第一种情况下)以及如何将链接绑定到 xap 文件(在第二种情况下)?
谢谢。
上面代码的实现可以在这里看到: http://www.lzel.net/wf_Currency_ASP.aspx
In my application I download some xml data file from some information center, add to this xml file (in aspx.cs) the column with images and all together I pass to the GridView in aspx file.
The same I want to do with xap files - I need to add them to the GridView according to the data context, but unfortunately there is a problem - object doesn't have object.Attributes like image.
Here is my code for adding images (gvCurrency is a GridView):
for (int i = 0; i < currency.Count; i++)
{
Image image = new Image();
image.Attributes.Add("src", "Images/Currency/" + xdoc.GetElementsByTagName("CURRENCYCODE")[i].InnerText + ".gif");
image.Attributes.Add("height", "15px");
image.Attributes.Add("width", "21px");
gvCurrency.Rows[i].Cells[0].Controls.Add(image);
}
Another possibility, as I think, is in binding links to the corresponding xap files in the aspx file, that in this case should seems like this (if I am not wrong):
<asp:GridView ID="gvCurrency" runat="server" AutoGenerateColumns="False" ...>
<Columns>
<asp:BoundField DataField="FLAG" />
<asp:BoundField HeaderText="Currency Name" DataField="NAME" />
...
<asp:TemplateField >
<ItemTemplate>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="10px" height="10px">
<param name="source" value="ClientBin/ArrowTriangle.xap"/>
...
</div>
</ItemTemplate>
</asp:TemplateField >
</Columns>
</asp:GridView>
So, my question is: how can I distribute xap files dynamically in runtime (in the first case) and how I can bind links to xap files (in the second case)?
Thanks.
The implementation of the code above is possible to see here: http://www.lzel.net/wf_Currency_ASP.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过javascript从服务器动态下载xap文件并将其放入表格的单元格中(在客户端渲染后)(jQuery是最好的)。
You can dynamic download xap file from server and put it in cell of table(after render at client side) by javascript(jQuery is best).