I am trying to populate an array with values from check boxes. I am using list check boxes. I spent hours to find the error. I am getting NullReferenceException was unhandled by user code. The error is pointing to i++ bit of code. When I comment test[i]=item.Value; and i++; lines I can alert the values that are selected but I cannot add them into the array.
protected void Button1_Click(object sender, EventArgs e)
{
string []test=null;
int i = 0;
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
// oneSelected = true;
test[i]=item.Value;
i++;
Response.Write("<script LANGUAGE='JavaScript' >alert('"+item.Value+"')</script>");
}
}
}