【发布时间】:2014-01-29 05:07:43
【问题描述】:
我正在尝试将此标签转换为字符串,但它似乎为空。这是错误消息:App_Web_2zs3gdg3.dll 中出现“System.NullReferenceException”类型的异常,但未在用户代码中处理 附加信息:对象引用未设置为对象的实例。
Label myDentistName = (Label)item.FindControl("Dentist.Dentist_Name");
sDentistName = myDentistName.Text;
Session["DentistName"] = sDentistName;
这就是它在.aspx中的定义方式
<td>
<asp:Label ID="dentistNameLabel" runat="server"
Text='<%# Eval("Dentist.Dentist_Name") %>' />
</td>
牙医姓名正确显示在屏幕上。
【问题讨论】:
-
你确定
item.FindControl不返回null吗? -
@Selman22 是的,它返回 null 但在屏幕上我看到的是 DentistName
-
@user3127986:是的,但是您正在寻找 ID 为“Dentist.Dentist_Name”的控件 - 查看您真正想要的控件的 ID...