asp.net根据以前的链接加载页面

时间:2013-06-24 04:15:37

标签: asp.net

我有一个图片很少的页面。还有一个页面,其中基于下拉链接的内容从db中提取。我目前有这个代码!ispostback

private void FillPage()
    {
        ArrayList categoryList = new ArrayList();

        if (!IsPostBack)
        {
            categoryList = ConnectionClass.GetMenuByCategory("Appetizer");
        }
        else
        {
            categoryList = ConnectionClass.GetMenuByCategory(DropDownList1.SelectedValue);
        }

是可能的,基于点击img来改变从开胃菜到img被选中的初始getmenubycategory。谢谢

2 个答案:

答案 0 :(得分:1)

试试这个:

private void FillPage()
    {
        ArrayList categoryList = new ArrayList();

        if (!IsPostBack)
        {
             if (Request.QueryString["category"] != null) 
             {
                 string categoryName = Request.QueryString["category"] as string;

                 if(!String.IsNullOrEmpty(categoryName)
                 {
                     switch(categoryName)
                     {
                         case "Entree":
                             categoryList = ConnectionClass.GetMenuByCategory("Entree");
                             break;
                         case "Dessert":
                             categoryList = ConnectionClass.GetMenuByCategory("Dessert");
                             break;
                         default:
                             categoryList = ConnectionClass.GetMenuByCategory("Appetizer");
                             break;
                     }
                 }
            }
        }
        else
        {
             categoryList = ConnectionClass.GetMenuByCategory(DropDownList1.SelectedValue);
        }

答案 1 :(得分:0)

您可以使用GET方法:

 <a href="go.aspx?img=1"><img src="img1.jpg/></a>
 <a href="go.aspx?img=2"><img src="img2.jpg/></a>

并在代码背后:

if(!String.IsNullOrEmpty(Request.QueryString["img"]))
    if(Request.QueryString["img"]=="1")
        //some initializing
    else
        //another initializing