2010-11-11 59 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