DATAGRID HELP!!!
-
Hi all, Can anyone help me out with this: in my datagrid's ItemDataBound event, I want the method to do something like this: private void onItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item? or e.Item.Cells[0].Controls[0]??? == a CheckBox object) // then do stuff else // do nothing } any ideas?
-
Hi all, Can anyone help me out with this: in my datagrid's ItemDataBound event, I want the method to do something like this: private void onItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item? or e.Item.Cells[0].Controls[0]??? == a CheckBox object) // then do stuff else // do nothing } any ideas?
Hi, I think there are two possibilities to do that: 1)
if(e.Item.Cells[0].Controls[0] is System.Web.UI.WebControls.CheckBox) { // do something }
2)if(e.Item.Cells[0].Controls[0].GetType().Equals(typeof(System.Web.UI.WebControls.CheckBox))) { // do something }
I don't know if the first one is correct, I always use the second possibility. But be sure to test if there is a cell or control and that it is not null before you use the GetType() method (otherwise there will be a NullReferenceException). Regards Sebastian