当前位置:编程学习 > C#/ASP.NET >>

菜鸟小问题

    protected void Button1_Click(object sender, EventArgs e)
    {
        ViewState.Clear();
        string key = " ShowType=" + Request.QueryString["type"] + " and";  解释一下这句  
        if (TextBox1.Text.Length > 0)
            key += string.Format(" Address like '%{0}%' and", TextBox1.Text); 我理解的这句是将TextBox1.Text内容发给{0} 然后进行地址查询 然后赋值给key
        if(TextBox2.Text.Length>0&&TextBox3.Text.Length==0)TextBox1.Text
            key += string.Format(" price > {0} and", TextBox2.Text);
        if (TextBox2.Text.Length == 0 && TextBox3.Text.Length > 0)
            key += string.Format(" price < {0} and", TextBox3.Text);
        if (TextBox2.Text.Length > 0 && TextBox3.Text.Length > 0)
            key += string.Format(" (price between {0} and {1}) and", TextBox2.Text,TextBox3.Text);
        if(DropDownList1.SelectedIndex>0)
            key += string.Format(" HouseType_ID={0} and", DropDownList1.SelectedValue);
        if(DropDownList2.SelectedIndex>0)
            key += string.Format(" Form='{0}' and", DropDownList2.SelectedItem.Text);
        if (DropDownList3.SelectedIndex > 0)
            key += string.Format(" Qu_ID={0} and", DropDownList3.SelectedValue);
        if (key.Length > 0)
            key = key.Substring(0, key.Length - 3);
        ViewState["key"] = key;
        Bind();
    }

<span style="font-weight:bold; color:White"><a href="house.aspx?type=1" style="font-size:20px; color:White">出租房源</a> | </span>
    <span style="font-weight:bold; color:White"><a href="house.aspx?type=2" style="font-size:20px; color:White">出售房源</a> | </span>  一个页面被两个链接使用 才出现了type 顺便解释下ViewState
希望大神们能给小弟详细解释一下 --------------------编程问答-------------------- string key = " ShowType=" + Request.QueryString["type"] + " and"; 解释一下这句
拼接字符串也要解释 --------------------编程问答-------------------- 当在同一个页面根据来源信息展示不同内容的时候,可以在地址栏加参数 ?type=0 的方式,然后在后台读取参数判断分别显示
Like this
string type = Request.QueryString["type"];


ViewState 在当前页面保存数据 --------------------编程问答--------------------  ViewState["key"] = " ShowType=" + Request.QueryString["type"];那这句是什么意思? 存储数据? --------------------编程问答-------------------- ViewState 类似缓存或者session --------------------编程问答-------------------- ViewState 我一直把它理解成隐藏域控件 --------------------编程问答-------------------- ViewState就类似于Cookie或者Session,用来存储值的
ViewState["key"] = " ShowType=" + Request.QueryString["type"]
的意思是将地址栏里的type的值存储在ViewState里
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,