i am trying to get multiple selected items from a asp:CheckBoxList but when i try to compare selected items with some value it says indexing is not allowed. here is the code and Underlined line contained errored code
// Cat_check is a CheckBoxList in which Multiple items are selected
for (int i = 0; i < cat_check.Items.Count; i++)
{
if (cat_check.SelectedItem != null)
{
string columnName =cat_check.SelectedItems[i].Text;
var column = gvRecoed.Columns.Cast<DataControlField>()
.FirstOrDefault(c => c.HeaderText == columnName);
if (column != null) column.Visible = true;
}
}
the idea is that the gvRecoed(GridView) column headers will be matched with CheckBoxList items and only matched columns will be set to visible true..