Hi All, I'm using a gridview where I can select multiple lines, I store the keynames of each line into a DataTable, but having trouble using the DataTable when it comes to activating the selected products.
Here is my code to add items to the DataTable:
if (Session["tblSelected"] == null) { DataColumn actID = new DataColumn("actID"); actID.DataType = Type.GetType("System.Int32"); tblSelected.Columns.Add(actID); DataColumn actStatus = new DataColumn("actStatus"); actStatus.DataType = Type.GetType("System.Int32"); tblSelected.Columns.Add(actStatus); DataColumn prodCode = new DataColumn("prodCode"); prodCode.DataType = Type.GetType("System.Int32"); tblSelected.Columns.Add(prodCode); DataColumn[] pCol = new DataColumn[1]; pCol[0] = actID; tblSelected.PrimaryKey = pCol; } else { tblSelected = (DataTable)Session["tblSelected"]; Session["tblSelected"] = null; } DataRow dRow = tblSelected.NewRow(); dRow["actID"] = activationID; dRow["actStatus"] = activationStatus; dRow["prodCode"] = productCode; if (!tblSelected.Rows.Contains(activationID)) { tblSelected.Rows.Add(dRow); } else { tblSelected.Rows.Find(activationID).Delete(); } Session["tblSelected"] = tblSelected;
|
I have defined my DataTable on the top
DataTable tblSelected = new DataTable();
|
My button has the following code to look through the table:
foreach (DataRow row in tblSelected.Rows) { // My code that activates the products.... }
|
Now the problem comes when I go into the foreach loop, it tels me that there are no items in tblSelected.
Anyone has any idea why after I selected a couple of rows, and confirmed they are added to the Datatable that they are not accessable from the button control?