我想知道是否有一种方法可以从GridView动态呈现模板字段的内容。
这就是网格的外观,也是我想要的,就是以某种方式在后面的代码中获得标签的呈现字符串。
<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>提前谢谢你,卡莉。
发布于 2011-05-13 00:29:18
获取控件内容的唯一方法是使用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。
https://stackoverflow.com/questions/5978171
复制相似问题