如何将字符串对象更改为标签控件

本文关键字:标签 控件 对象 字符串 | 更新日期: 2023-09-27 18:35:46

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

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;

如何将字符串对象更改为标签控件

使用标签的 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;

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