problem with foreach loop in Checkboxes datagrid
Hi All,
Below is the full code of a method which calls a saving stored procedure.Before doing this a foreach method with a nested loop for each column searches the datagrid for checked and uncheked boxes ( which it does successfully). The problem is basically it always hit's the catch statement i have thrown. It exits the foreach statement then goes upto "calendar.saveCalendar ....." At this point it then goes to the finally statement but it returns to the foreach statement. Any ideas why this might be happening?
Cheers
mbge9pjb
public void btnSave_Click(object sender, System.EventArgs e)
{
try
{
foreach(DataGridItem dgi in EditCalendar.Items)
{
for ( int i =0; i< checkedMonthOfYear.Length; i++)
{
CheckBox chkEfaPeak = (CheckBox) dgi.FindControl(checkedMonthOfYear[i]);
bool newState = chkEfaPeak.Checked;
DataSet years = getDataSetFromSessionYears();
years.Tables[0].Rows[dgi.DataSetIndex][months[i]]= (newState ? "Y": "N");
}
}
Int32 idCalendar = Int32.Parse.lstCalendars.Items[ lstCalendars.SelectedIndex].Value);
Int32 idCalendarVersion = Int32.Parse( hiddenCalendarVersionId.Value);
Int16 retcode;
DataSet changes = getDataSetFromSessionYears().GetChanges( DataRowState.Modified);
Calendar calendar = new Calendar( Configuration.getConnStr());
calendar.saveCalendar idCalendar, idCalendarVersion, SecurityManager.getUserID(),changes, out retcode);
}
catch (NullReferenceException )
{
// makes sure the method catches datagrid referencing null objects
Response.Redirect("../configuration/Peak_Scaling.aspx");
}
finally
{
setDataSetToSessionYears(null);
}
}
|