how to pass arraylist to switch statement
i want to pass arraylist to switch statement , below is the code:
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
ArrayList myList = new ArrayList();
foreach (ListItem listitem in CheckBoxList1.Items)
{
if (listitem.Selected)
myList.Add(listitem.Value);
}
ViewState["myList"] = myList;
CurrentPage = 0;
BindGrid();
}
private void BindGrid()
{
DataTable dt = null;
switch (ViewState["myList"]) //gives an error
{ case myList[1]: dt = caravans.GetSelectedFilter(myList); break;
default: dt = caravans.GetAllCaravans(); break;
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 12;//add the page index when item exceeds 12 //Convert.ToInt16(ddlPageSize.SelectedValue);
pds.CurrentPageIndex = CurrentPage;
DataList1.RepeatC开发者_StackOverflow中文版olumns = 4; // 4 items per line
DataList1.RepeatDirection = RepeatDirection.Horizontal;
DataList1.DataSource = pds;
DataList1.DataBind();
// lnkbtnNext.Enabled = !pds.IsLastPage;
ImageButton2.Enabled = !pds.IsLastPage;
// lnkbtnPrevious.Enabled = !pds.IsFirstPage;
doPaging();
}
From MSDN:
The governing type of a switch statement is established by the switch expression. If the type of the switch expression is sbyte, byte, short, ushort, int, uint, long, ulong, char, string, or an enum-type, then that is the governing type of the switch statement. Otherwise, exactly one user-defined implicit conversion (Section 6.4) must exist from the type of the switch expression to one of the following possible governing types: sbyte, byte, short, ushort, int, uint, long, ulong, char, string. If no such implicit conversion exists, or if more than one such implicit conversion exists, a compile-time error occurs.
The Switch Statement
精彩评论