you must get the current item first. e is just a parameters of button click event.but it's not listitem's.
try in your update function like this:Button btn=(Button)sender;
DataListItem item =(DataListItem)btn.Parent.Parent;
....
in other parts you can use item instead of e.Item writen by you.

解决方案 »

  1.   

    按照你的方法,我把Update函数改成:void Update(object sender, EventArgs e)
    {
    Button btn=(Button)sender;
    DataListItem item =(DataListItem)btn.Parent.Parent;
    string number = item.Cells[0].Text;
    string at1 = ((CheckBox)item.Cells[1].Controls[0]).Checked;
    string at2 = ((CheckBox)item.Cells[2].Controls[0]).Checked;
    OleDbConnection DangManaConn = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source ="+Server.MapPath("DangMana.mdb"));
    string myUpdate = "UPDATE testtable SET attr1=at1,attr2=at2 WHERE numb=number";
    OleDbCommand myCommand = new OleDbCommand(myUpdate,DangManaConn);
    myCommand.Connection.Open();
    myCommand.ExecuteNonQuery();
    DangManaConn.Close();
    Page_Load(null,new EventArgs());
    }编译信息是:编译器错误信息: CS0117: “System.Web.UI.WebControls.DataListItem”并不包含对“Cells”的定义。
      

  2.   

    DataList中是没有Cell的
    这样来获取item下的控件
    CheckBox cb1 = (CheckBox)item.FindControl("cb1");
    如果你还要获取numb的内容的话,就把numb行在一个Label里