日期:2014-05-18  浏览次数:21665 次

CS0103: 当前上下文中不存在名称“Label1”
C# code

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
            ID号:
                <asp:Label ID="order_idLabel" runat="server" Text='<%# Eval("id") %>' />
                <br />
                订单号:
                <asp:Label ID="order_porderLabel" runat="server" Text='<%# Eval("order_id") %>' />
                <br />
                付款状态:
                <asp:Label ID="pay_stateLabel" runat="server" Text='<%# Eval("pay_state") %>' />
                <br />
                处理状态:
                <asp:Label ID="send_markLabel" runat="server" Text='<%# Eval("send_mark") %>' />
                <br />
                <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem Value="">--请选择--</asp:ListItem>
                <asp:ListItem Value="0">取消订单</asp:ListItem>
                <asp:ListItem Value="1">等待审核</asp:ListItem>
                <asp:ListItem Value="2">正在备货</asp:ListItem>
                <asp:ListItem Value="3">已发货</asp:ListItem>
                <asp:ListItem Value="4">交易完成</asp:ListItem>
                <asp:ListItem Value="5">等待付款</asp:ListItem>
                <asp:ListItem Value="6">系统取消</asp:ListItem>
                <asp:ListItem Value="7">确认收货</asp:ListItem>
                </asp:DropDownList> 
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="修改状态" />
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <br />
            </ItemTemplate>
        </asp:DataList>
        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:test_userConnectionString %>" 
            
            SelectCommand="SELECT TOP 10 [order_id], [pay_state], [send_mark], [id] FROM [OrderSend] ORDER BY id DESC">
        </asp:SqlDataSource>
    </div>
    </form>
    
</body>
</html>






C# code

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "OK";
    }
}