开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜