Hello,
I'm trying to access the values from a data grid. I have a data grid control, and have use the OnItemCommand Event as follows:
Code:
private void dgrResults_ItemCommand(object sender, DataGridCommandEventArgs e) {
DataGrid objGrid = (DataGrid) sender;
switch (e.CommandName.ToLower()) {
case "cancel":
objGrid.EditItemIndex = -1;
BindGrid();
break;
case "delete":
//Where error occurs, says "cannot convert string to int")
TextTable.Rows.Remove(TextTable.Rows.Find((int) e.Item.Cells[0].Text));
BindGrid();
break;
case "edit":
objGrid.EditItemIndex = e.Item.ItemIndex;
BindGrid();
break;
case "update":
TextBox objText = (TextBox) e.Item.Cells[1].Controls[0];
DropDownList objStyle = (DropDownList) e.Item.Cells[2].Controls[0];
//No error here, but it wasn't working above so I assume it won't work here also
UpdateData((int) e.Item.Cells[0].Text, objText.Text, objStyle.SelectedValue);
BindGrid();
break;
}
objGrid = null;
}
Where I get the ID (e.Item.Cells[0].Text) which is a bound column, it says cannot convert string to int (see comments in code which specify the errors). I'm guessing it's because it's returning an empty string, and it can't convert it to a number... but I don't know. Any ideas?
Thanks,
Brian Mains