删除操作: protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e) { string strID = DataList1.DataKeys[e.Item.ItemIndex].ToString(); Assign car = new Assign(); if (DataList1.Items.Count == 1) { string strUrl = "AssignList.aspx?usedate=" + DateTime.Parse(lblLeaveTime.Text.ToString()).ToString("yyyy-MM-dd"); car.DeleteCarSendFormID(strID, intAssignId); car.DeleteCarSendForm(intAssignId); Response.Write("<mce:script language='javascript'><!-- window.close();window.opener.location.href='" + strUrl + "'; // --></mce:script>"); //Response.Write("<mce:script language='javascript'><!-- window.location.href='AssignList.aspx';window.opener.location.href=window.opener.location.href; // --></mce:script>"); } else { car.DeleteCarSendFormID(strID, intAssignId); Response.Write("<mce:script language='javascript'><!-- window.location.href=window.location.href // --></mce:script>"); } DataList1.DataBind(); } 更新操作: protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e) { // Read in the ProductID from the DataKeys collection int productID = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]); // Read in the product name and price values TextBox productName = (TextBox)e.Item.FindControl("ProductName"); TextBox unitPrice = (TextBox)e.Item.FindControl("UnitPrice");//查找对应的控件 string productNameValue = null; if (productName.Text.Trim().Length > 0) productNameValue = productName.Text.Trim(); decimal? unitPriceValue = null; if (unitPrice.Text.Trim().Length > 0) unitPriceValue = Decimal.Parse(unitPrice.Text.Trim(), System.Globalization.NumberStyles.Currency); // Call the ProductsBLL's UpdateProduct method... ProductsBLL productsAPI = new ProductsBLL(); productsAPI.UpdateProduct(productNameValue, unitPriceValue, productID);//调用BLL中的重载方法 // Revert the DataList back to its pre-editing state DataList1.EditItemIndex = -1; DataList1.DataBind(); }