Click to See Complete Forum and Search --> : How to access table cells without being told 'is inaccessible due to its protection'


Tomie
12-15-2005, 08:26 AM
Hello,

I have the following sub-routine which retrieves the details of a shopping cart.


void getCartDetails() {
string orderID;
orderID = Convert.ToString(Session["orderID"]);
string queryString = "SELECT Products.ProductID, Products.ProductName, tCart.quantity, Products.UnitPrice, [UnitPrice]*[quantity] AS Amount FROM Products INNER JOIN tCart ON Products.ProductID = tCart.productCode WHERE (((tCart.orderID)='" + orderID + "'));";
OleDbDataReader dataReader = getReader(queryString); // call getReader() method to return the result (after executing) the SQL statement
dlDetails.DataSource = dataReader; // set the result of the datareader into datagrid
dlDetails.DataBind();
dataReader.Close();

if(dlDetails.Items.Count == 0) {
dlDetails.Visible = false;
lbl1.Text = "Your basket is empty.";
}

int i;
double sum = 0.0;

for(i = 0; i < dlDetails.Items.Count; i++) {
sum += Convert.ToDouble(dlDetails.Items[i].cells[4]);
}

lbl2.Text = sum;
}

I just have one problem with the for statement at the bottom of the sub, it is supposed to loop around and pick up the 'amount' (quantity * unit price) value in the cell of each item in the basket. However, when I run the code it reports:

CS0122: 'System.Web.UI.WebControls.TableRow.cells' is inaccessible due to its protection level

Does anyone know of this error, is there any work-around please?

Thank you for any advice !