dodgerfan
asked on
IndexOutOfRangeException in one environment
I'm getting an IndexOutOfRangeException in some of my C# code. The problem is that the code works perfectly in my development environment. On the Testing machine, I get the error. They of course work off of different databases, but they are the same thing, down to the data. Any idea what coudl cause it to work in one place but not the other. The offending code is below. I'm opeing as ASP.Net form that has two CheckBoxList controls and setting the checkboxes based on the values stored in the DB. The code is in the Page_Load event. Thanks for any help.
CheckBoxList Control = (CheckBoxList)Form1.FindCo ntrol("Con trol");
SqlConnection objConn = new SqlConnection("myconnectio n");
SqlCommand objCmd = new SqlCommand("select * from Field_Lookup", objConn);
objConn.Open();
Conrtol.DataSource = objCmd.ExecuteReader(Comma ndBehavior .CloseConn ection);
Control.DataBind();
objCmd = new SqlCommand("select * from vw_tierFields where RecID = " + Session["RecID"], objConn);
objConn.Open();
SqlDataReader objReader = objCmd.ExecuteReader();
while (objReader.Read())
{
ListItem currentCheckBox = Control.Items.FindByValue( objReader[ "Control"] .ToString( ));
if (currentCheckBox != null)
{
currentCheckBox.Selected = true;
}
objReader.Close();
CheckBoxList Control = (CheckBoxList)Form1.FindCo
SqlConnection objConn = new SqlConnection("myconnectio
SqlCommand objCmd = new SqlCommand("select * from Field_Lookup", objConn);
objConn.Open();
Conrtol.DataSource = objCmd.ExecuteReader(Comma
Control.DataBind();
objCmd = new SqlCommand("select * from vw_tierFields where RecID = " + Session["RecID"], objConn);
objConn.Open();
SqlDataReader objReader = objCmd.ExecuteReader();
while (objReader.Read())
{
ListItem currentCheckBox = Control.Items.FindByValue(
if (currentCheckBox != null)
{
currentCheckBox.Selected = true;
}
objReader.Close();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.