回 帖 发 新 帖 刷新版面

主题:是否代码有错?一段很简单的代码,但我不知道是否有错

一段很简单的代码,但我不知道是否有错,我运行时,老得到以下错误提示,真的不知道是什么原因啊!!!:
Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.Label'

Source Error:



Line 4:      void Page_Load()
Line 5:          {
Line 6:          time=DateTime.Now.ToString();
Line 7:          }
Line 8:  


Source File: Ch01\punctual.aspx    Line: 6



Show Detailed Compiler Output:

Show Complete Compilation Source:

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573




原代码:
<%@ Page Language="C#" %>
<script runat="server">

    void Page_Load()
        {
        time=DateTime.Now.ToString();
        }

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        In WebServerLand the time is currently:
        <asp:Label id = "time" runat="server"/>
        <!-- Insert content here -->
    </form>
</body>
</html>

回复列表 (共4个回复)

沙发

time.Text=DateTime.Now.ToString();

板凳

谢谢谢谢!
在发帖之后我乱试了一下,被我试对了,不过还是很感谢您

3 楼

按照字面直译,楼主满可以自己解决问题的:)
Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.Label'

不能 暗中的 转换 类型 'string' 到 'System.Web.UI.WebControls.Label'
你的意思是让标签显示时间,但是标签不能直接被赋予时间,必须是标签的文字
才能被赋予时间值:)

4 楼

我水平太菜了,请见谅!呵呵

我来回复

您尚未登录,请登录后再回复。点此登录或注册