我要把datalist中的label中的只取出来,但是老是提示“错误 CS1061: “ASP.leftroom_leftroom_aspx”不包含“DataList1_ItemDataBound”的定义,并且找不到可接受类型为“ASP.leftroom_leftroom_aspx”的第一个参数的扩展方法“DataList1_ItemDataBound”(是否缺少 using 指令或程序集引用?)”,我已经定义了了 啊,
代码如下:
<asp:DataList ID="DataList1" runat="server" DataKeyField="房间号" 
                                            DataSourceID="SqlDataSource1" RepeatColumns="4" RepeatDirection="Horizontal" 
                                            Width="1016px" onselectedindexchanged="DataList1_SelectedIndexChanged" 
                                            BorderColor="#3399FF" onitemcommand="DataList1_ItemCommand" 
                                            onitemdatabound="DataList1_ItemDataBound"  >
我已经定义了onitemdatabound="DataList1_ItemDataBound"了呀,,,原因在哪里呢?
                                           
                  

解决方案 »

  1.   

    定义onitemdatabound="DataList1_ItemDataBound"有什么用,你的cs文件中必须有DataList1_ItemDataBound的实现代码
      

  2.   


    我弄了以后报这个错是怎么回事啊
    异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
    行 56:     protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    行 57:     {
    行 58:         Label 房间号Label = e.Item.FindControl("房间号") as Label; string restrant_ID = 房间号Label.Text;
    行 59:     }
    行 60: }
    后台代码:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml.Linq;
    using System.Data.SqlClient;using CrystalDecisions.Shared;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Web;public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {       
        }
        
       
        protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {    }
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (Session["uid"] == null)
            {
                RegisterStartupScript("", "<script>alert('你尚未登录!')</script>");
            }
            else
            {
                           Response.Redirect("http://localhost:49261/HMSTRYtry/Order/Order.aspx?restrant_ID=");
                
     
            }    }    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            
        }
        protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
        {    }
        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Label 房间号Label = e.Item.FindControl("房间号") as Label; string restrant_ID = 房间号Label.Text;
        }
    }
      

  3.   

     后台版定代码:1、protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Label 房间号Label = e.Item.FindControl("房间号Label") as Label;        string restrant_ID = 房间号Label.Text.ToString();
        }
    2.protected void Button3_Click(object sender, EventArgs e)
        {
            if (Session["uid"] == null)
            {
                RegisterStartupScript("", "<script>alert('你尚未登录!')</script>");
            }
            else
            {
                Button 房间号Lable = (Button)sender;
                Session["房间号"] = 房间号Lable.CommandArgument;
                Response.Redirect("http://localhost:49261/HMSTRYtry/Order/Order.aspx?id=xx");        }