2011-05-12 68 views
0

我想知道是否有方法從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> 

在此先感謝, 卡莉。

+0

你是說你想要Label控件的HTML嗎? – 2011-05-12 13:05:39

+0

這將是好的。 – calin 2011-05-12 13:48:38

+0

我在問這是你想做什麼,或者如果我誤解了這個問題。那是你想要做的,還是其他的? – 2011-05-12 14:24:01

回答

0

好了,拿到的一個控件的內容的唯一方法是使用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。