Hi devonl,
Thanks for the reply. Nearly a carbon-copy of the code I have! :D
Code:
public void OnUpdate(object source, DataListCommandEventArgs e)
{
/* Get the updated values from the form */
int vehicleID = Convert.ToInt32(vehiclesDataList.DataKeys[e.Item.ItemIndex].ToString());
/* check date given is valid otherwise use todays date */
DateTime date;
string dateString = DataValidation.ValidateDate(((TextBox)(e.Item.FindControl("txtDate"))).Text);
if (dateString != null)
{
date = Convert.ToDateTime(dateString);
}
else
{
date = DateTime.Now;
}
/* check price is valid otherwise set to 0 - maybe change this? */
decimal price;
string priceString = DataValidation.ValidatePrice(((TextBox) e.Item.FindControl("txtPrice")).Text);
if(priceString != null)
{
price = Convert.ToDecimal(priceString);
}
else
{
price = 0;
}
/* Get the other fields */
string manufacturer = ((TextBox) e.Item.FindControl("txtManufacturer")).Text;
string model = ((TextBox) e.Item.FindControl("txtModel")).Text;
string regNumber = ((TextBox) e.Item.FindControl("txtRegNumber")).Text;
string stockNumber = ((TextBox) e.Item.FindControl("txtStockNumber")).Text;
string orderNumber = ((TextBox) e.Item.FindControl("txtOrderNumber")).Text;
bool cancelled = ((CheckBox) e.Item.FindControl("chkIsCancelled")).Checked;
bool readyToInvoice = ((CheckBox) e.Item.FindControl("chkIsReadyToInvoice")).Checked;
int driverID = Convert.ToInt32(((DropDownList) e.Item.FindControl("lstDriver")).SelectedValue);
int transporterID = Convert.ToInt32(((DropDownList) e.Item.FindControl("lstTransporter")).SelectedValue);
int version = Convert.ToInt32(((Label) e.Item.FindControl("version")).Text);
/* Get the session */
ISession session = SessionHandler.CurrentSession;
/* Get the selected driver & transporter */
Driver driver = DataAccessLayer.GetDriverByID(driverID, session);
Transporter transporter = DataAccessLayer.GetTransporterByID(transporterID, session);
Vehicle vehicle = new Vehicle();
vehicle.ID = vehicleID;
vehicle.Version = version;
/* Update vehicle fields here */
// chopped for brevity
if(vehicle.IsCancelled)
{
/* Delete the vehicle */
SessionHandler.DeleteObject(vehicle);
}
else
{
/* Update vehicle */
SessionHandler.UpdateObject(vehicle);
}
/* Unset edit row */
this.vehiclesDataList.EditItemIndex = -1;
BindGrid();
}
This is throwing the following error:
Code:
another object with the same id was already associated with the session: [Vehicle#11]
In your code how is "this._question" set and where is it stored? If in session how does your code know to go to the database for a new version?
I will take another look at my code to work out why the DataItem property is not returning anything. It can't all be null as I am getting the values from the controls ok just need to get my business object back!