Find Control Text (ASP.NET/C#)
Trying to pull the text value of the label that is dynamically populated by a SQL database. Any help would be greatly appreciated!
ASP.NET
<asp:Label ID="PlatformNa开发者_高级运维me" Text='<%# DataBinder.Eval(Container.DataItem, "PlatformName") %>' runat="server" />
C# Code Behind (Which gives me the object, not the string value in the label)
string strPlatform = GameGrid.Rows[counter].FindControl("PlatformName").ToString()
FindControl will return a control (of type Control), so you will need to cast it to a Label to access the Text property.
Try:
Label lbl = GameGrid.Rows[counter].FindControl("PlatformName") as Label;
if (lbl != null)
strPlatform = lbl.Text;
精彩评论