Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找控件文本(ASP.NET/C#)_C#_Asp.net - Fatal编程技术网

查找控件文本(ASP.NET/C#)

查找控件文本(ASP.NET/C#),c#,asp.net,C#,Asp.net,尝试提取由SQL数据库动态填充的标签的文本值。任何帮助都将不胜感激 ASP.NET FindControl将返回一个控件(控件类型),因此需要将其强制转换为标签才能访问Text属性 尝试: <asp:Label ID="PlatformName" Text='<%# DataBinder.Eval(Container.DataItem, "PlatformName") %>' runat="server" /> string strPlatform = GameGrid

尝试提取由SQL数据库动态填充的标签的文本值。任何帮助都将不胜感激

ASP.NET


FindControl将返回一个控件(控件类型),因此需要将其强制转换为标签才能访问Text属性

尝试:

<asp:Label ID="PlatformName" Text='<%# DataBinder.Eval(Container.DataItem, "PlatformName") %>' runat="server" />
string strPlatform = GameGrid.Rows[counter].FindControl("PlatformName").ToString() 
Label lbl = GameGrid.Rows[counter].FindControl("PlatformName") as Label;
if (lbl != null)
    strPlatform = lbl.Text;