DataGrid update

liunx

Guest
Hi!!!

I am using C# DataGrid

When I update a record in there, the updated row for some reason jumps down and become the last, even if it was first.

The code i am using is:

public void ItemsCart_Update(Object sender, DataGridCommandEventArgs e)
{
//To delete old record, we will filter our data view so that
//the old record is the only one that is visible.
//We get the ISBN using the Cells collection.
CartView.RowFilter = "ISBN=" + e.Item.Cells[3].Text;

if(CartView.Count > 0)
{
CartView.Delete(0);
}
//Now that the old record is gone, we can turn off our row filter
CartView.RowFilter = "";

//Create the new row
DataRow dr = TableCart.NewRow();

string strID = e.Item.Cells[0].Text;
dr["ID"] = strID;

string strImagePath = objMKBookShop.GetImagePath("ImagePath");
string strImageName = objMKBookShop.GetProductRecord("INVIMAGE", "IMAGE1", "SELECT * FROM INVIMAGE WHERE UNIQUEID = '" + strID + "'");

dr["Picture"] = strImagePath + "/" + strImageName;;
dr["Title"] = e.Item.Cells[2].Text;
dr["ISBN"] = e.Item.Cells[3].Text;
string strQuantity = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
dr["Quantity"] = strQuantity;
string strSubtotal = objMKBookShop.GetProductRecord("INVENTRY", "PRICE3", "SELECT * FROM INVENTRY WHERE UNIQUEID = '" + strID + "'");
double dSubtotal = double.Parse(strSubtotal);
double dNewSubtotal = int.Parse(strQuantity) * dSubtotal;
string strNewSubtotal = dNewSubtotal.ToString("#0.00");
dr["Subtotal"] ="$" + strNewSubtotal;

double dTotal = 0;
int iTotalQuantity = 0;

TableCart.Rows.Add(dr);

foreach(DataRow row in TableCart.Rows)
{
int iQuantity = (int)row["Quantity"];
iTotalQuantity = iTotalQuantity + iQuantity;
string strSubTotal = row["Subtotal"].ToString();
string strDollarSign = strSubTotal.Substring(0, 1);
double dDollarValue = double.Parse(strSubTotal.Substring(1));
dTotal = dTotal + dDollarValue;
}

Session["Quantity"] = iTotalQuantity;
Session["Total"] = dTotal.ToString();

TotalLabel.Text = "Total: $" + dTotal.ToString("#0.00");

Session["SessionCart"] = TableCart;
//CartView = new DataView(TableCart);
ItemsCart.EditItemIndex = -1;
BindGrid();
}

Please adviceThink betterThis might have something to do with smartnavigation. You might try disableing that in your web.config or just on your page directive
smartnavigation="false"
 
Back
Top