0
我想傳遞的ArrayList到switch語句,下面是代碼:如何通過數組列表切換聲明
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.RepeatColumns = 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();
}
有沒有其他的辦法可以達致這 – 2011-04-07 16:22:53
嘗試使用if,else if語句可 – dhirschl 2011-04-07 16:25:04
我可以通過ArrayList中通過視圖狀態 – 2011-04-07 16:26:45