2010-11-11 27 views
2

嘗試拉取由SQL數據庫動態填充的標籤的文本值。任何幫助將不勝感激!查找控制文本(ASP.NET/C#)

ASP.NET

<asp:Label ID="PlatformName" Text='<%# DataBinder.Eval(Container.DataItem, "PlatformName") %>' runat="server" /> 

C#代碼隱藏(這使我的對象,而不是字符串值的標籤)

string strPlatform = GameGrid.Rows[counter].FindControl("PlatformName").ToString() 

回答

7

的FindControl將返回一個控件(類型爲Control),因此您需要將它轉換爲Label來訪問Text屬性。

嘗試:

Label lbl = GameGrid.Rows[counter].FindControl("PlatformName") as Label; 
if (lbl != null) 
    strPlatform = lbl.Text; 
+0

偉大工程的感謝! – KennyH 2010-11-11 13:48:03