你的ListBox是WinControl還是WebControl?

解决方案 »

  1.   

    using System.Data;DataSet ds = new DataSet();
    ds.ReadXml("yourxml.xml");
    ListBox1.DataSource = ds.Tables[0].DefaultView;
    ListBox1.DisplayMember = "someNodeName";
    //ListBox1.DataTextField= "someNodeName"; //if webform
    ListBox1.DataBind();
      

  2.   

    我在调试的时候出来这句话
    An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exeAdditional information: Object reference not set to an instance of an object.
    箭头指向这句 ->ListBox1.DataSource = ds.Tables[0].DefaultView;
      

  3.   

    你加端點看看
    ds.Tables[0]是否為null
      

  4.   

    这句话过不去,ds.Tables[0]没有取值
      

  5.   

    xml的路径?是不是要给出完整的路径?
      

  6.   

    Application.StartupPath + "\yourxml.xml"
      

  7.   

    Application.StartupPath + "\yourxml.xml"
      

  8.   

    Application.StartupPath + @"\yourxml.xml"
    sorry :)
      

  9.   

    关闭,再重开刚才的问题没了,但是ds.Tables[0]的值是{System.Data.DataTableCollection}
      

  10.   

    ?
    你是不是查看的是ds.Tables的值呀
    ds.Tables[0]應該是System.Data.DataTable