动态呈现TemplateField的内容
问题描述:
我想知道是否有方法从GridView动态呈现模板字段的内容。动态呈现TemplateField的内容
这是网格的外观和我想要的,是以某种方式在代码后面获取标签的呈现字符串。
<asp:GridView runat="server" ID="simpleGrid" AutoGenerateColumns="false" Visible="false">
<Columns>
<asp:TemplateField HeaderText="Templated Date">
<ItemTemplate>
<asp:Label ID="firstLabel" Text='<%# Eval("Date") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
在此先感谢, 卡莉。
答
好了,拿到的一个控件的内容的唯一方法是使用RenderControl方法,通过这样的:
StringWriter strings = new StringWriter();
HtmlTextWriter html = new HtmlTextWriter(strings);
Label label = //find the reference to the label
label.RenderControl(html);
这应该推控件的标记进入的HTML编写,并通过字符串容易提取作家。这是一种方式。否则,除了在客户端JavaScript中,不能直接访问其HTML。
HTH。
你是说你想要Label控件的HTML吗? – 2011-05-12 13:05:39
这将是好的。 – calin 2011-05-12 13:48:38
我在问这是你想做什么,或者如果我误解了这个问题。那是你想要做的,还是其他的? – 2011-05-12 14:24:01