如何将String对象更改为Label控件

时间:2015-01-01 14:01:49

标签: c# asp.net

我有一个从数据库查询的字符串对象。我想要的是如何将字符串对象转换为Label控件。我尝试如下所示,但它无法正常工作。

String QueryMenu =" Select MenuLocation from tblMenu where MenuId='" + PermissionArray[i] + "'";
SqlCommand MenuExe = new SqlCommand(QueryMenu, con);
MenuExe.ExecuteScalar();
Label myLabel = this.FindControl("MenuExe") as Label;........1


myLabel.Visible = true;

1 个答案:

答案 0 :(得分:0)

使用标签的Text属性进行设置:

String QueryMenu =" Select MenuLocation from tblMenu where MenuId='" + PermissionArray[i] + "'";
SqlCommand MenuExe = new SqlCommand(QueryMenu, con);
Label myLabel = this.FindControl("MenuExe") as Label;       
myLabel.Text = (string)MenuExe.ExecuteScalar();
myLabel.Visible = true;

这假设查询返回一个字符串