Hello,
I need to use a for loop instead of a foreach loop to update all the TextBox values(txtQuantity), but I don't know how to reference/cast the GridDataItem to the RadGrid while not being inside of a RadGrid event.
This OnClick works on the most part. But if evaluates to false it just continues. I need it to stop.
Thank you in advance,
Ronnie
I need to use a for loop instead of a foreach loop to update all the TextBox values(txtQuantity), but I don't know how to reference/cast the GridDataItem to the RadGrid while not being inside of a RadGrid event.
This OnClick works on the most part. But if evaluates to false it just continues. I need it to stop.
| protected void btnUpdateCart_Click(object sender, EventArgs e) |
| { |
| // TODO: Use for loop to stop when an expression evaluates to false. |
| //for (int i = 0; i < grdCart.Items.Count; i++) |
| foreach (GridDataItem dataItem in grdCart.MasterTableView.Items) |
| { |
| // TODO: Cast (GridDataItem)dataItem here and remove foreach |
| string strItemId = dataItem.GetDataKeyValue("ID").ToString(); |
| RadTextBox txtQuantity = (RadTextBox)dataItem.FindControl("txtQuantity"); |
| int itemId, quantity; |
| bool success = false; |
| if (Int32.TryParse(strItemId, out itemId) && Int32.TryParse(txtQuantity.Text, out quantity)) |
| { |
| success = _cartItem.Update(itemId, quantity); |
| } |
| lblFeedback.Text = success ? "Your cart has been successfully updated!" : "There was an error updating your cart.<br />Please verify that the quantity value is a number and try again."; |
| } |
| grdCart.Rebind(); |
| } |
Thank you in advance,
Ronnie