If DataTable Has Rows
Posted on 2004-09-24
How do I write a HasRows for my DataTable? If there is a row I want to perform a delete but if not, just write something.
I tried saying if e.Item.ItemIndex >-1 and it works until there are no rows then if i press refresh I get an error: "There is no row at position 0" so I think I should say if the table has any rows or not. This is what I am trying to avoid. if there are no rows it should just say "Your shopping cart is empty" instead of going into the if statment to try and do a Delete.
void DeleteItem(Object Sender,DataGridCommandEventArgs e)
//---------Get DataTable from Session:
//--------IF rows exist then do delete ELSE just write "Your shopping cart is empty"
//---------I'm trying to prevent error on refresh. If there are no rows it should only go to Response.Write but I'm getting an error now because it still enters if statement
//--------SHOULD I TRY IF tblCart HAS ROWS HERE INSTEAD of e.Item.ItemIndex?----
if (e.Item.ItemIndex >-1)
Response.Write("Your shopping cart is empty");