C# Datagrid Help foreach statement checkboxes
Hi All,
Basically i have the following code. When the foreach statement is finished and the method continues, at the end of the method it re-enters the foreach statement ( which i don't want to happen as i have all the data i need ) The error i am getting is 'Object reference not set to an instance of an object'. However, more importantly how do i stop the code stepping into the foreach statement for a second time? Thanks, mbge9pjb
public void btnSave_Click(object sender, System.EventArgs e)
{
if ( Page.IsValid)
{
bool newState = false;
foreach(DataGridItem dgi in EditCalendar.Items)
{
for ( int i =0; i <checkedMonthOfYear.Length; i++)
{
CheckBox chkEfaPeak = (CheckBox) dgi.FindControl(checkedMonthOfYear[i]);
newState = chkEfaPeak.Checked;
DataSet years = getDataSetFromSessionYears();
years.Tables[0].Rows[ dgi.DataSetIndex][months[i]]= (newState ? "Y": "N");
EditCalendar.EditItemIndex = -1;
}
}
//some nmore code here but ultimately i think the problem is with the above sample. Once the nested loop has finished and continues with the method, it returns back to the 'foreach' statement which i don't want to happen
|