再开头加上:
DataList MyDataList = new DataList();
就可以了,问题解决了,加分吧!!!

解决方案 »

  1.   

    如果是在页面拖进去的DataList会自动生成protected System.Web.UI.WebControls.DataList DataList1;,如果是自己在后台写,则需要new一个DataList,即如larrybest(小飞)所说DataList MyDataList = new DataList();
      

  2.   

    解决一定散分,但是还没有搞定了阿。在那里加?
    protected System.Web.UI.WebControls.DataList MyDataList;
    private String _category = ""; public String Category 
    {
    get 
    {
    return _category;
    }
    set 
    {
    _category = value;
    }
    } private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection myConnection = new SqlConnection("data source = 10.2.6.103;database=pubs;uid=sa;pwd=sa;");
    SqlDataAdapter myCommand = new SqlDataAdapter("select * from Titles where type='" + _category + "'", myConnection); DataSet ds = new DataSet();
    myCommand.Fill(ds, "Titles"); MyDataList.DataSource = ds.Tables["Titles"].DefaultView;
    MyDataList.DataBind();
    }
      

  3.   

    解决一定散分,但是还没有搞定了阿。在那里加?
    protected System.Web.UI.WebControls.DataList MyDataList;
    private String _category = ""; public String Category 
    {
    get 
    {
    return _category;
    }
    set 
    {
    _category = value;
    }
    } private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection myConnection = new SqlConnection("data source = 10.2.6.103;database=pubs;uid=sa;pwd=sa;");
    SqlDataAdapter myCommand = new SqlDataAdapter("select * from Titles where type='" + _category + "'", myConnection); DataSet ds = new DataSet();
    myCommand.Fill(ds, "Titles"); MyDataList.DataSource = ds.Tables["Titles"].DefaultView;
    MyDataList.DataBind();
    }