Viewstate 的用法

 1.做了开发这么久,居然不知道Viewstate是怎么用的!真悲剧……
Viewstate主要是用来保留页面数据的。下面是某一种情况的用法。
        private string MCategory

        {

            set

            {

                ViewState["MCategory"] = value;

            }

            get

            {

                if (ViewState["MCategory"] == null)

                    return "";

                else

                    return (string)ViewState["MCategory"];

            }

        }

        //save market category information

        private string KCategory

        {

            set

            {

                ViewState["KCategory"] = value;

            }

            get

            {

                if (ViewState["KCategory"] == null)

                    return "";

                else

                    return (string)ViewState["KCategory"];

            }

        }

 附带一个添加多行的方式,以前见过,没有记下来,都忘记了,悲剧……

 

    private string GetCondition

    {

        get

        {

            return @"<Where>  

          <And>  

            <And>  

             <Geq>  

                   <FieldRef Name='Created' />  

                    <Value Type='DateTime'>{0}</Value>  

             </Geq>  

             <Leq>  

                 <FieldRef Name='Created' />  

                <Value Type='DateTime'>{1}</Value>  

             </Leq>  

             </And>  

              <Gt>  

               <FieldRef Name='ID' />  

               <Value Type='Counter'>0</Value>  

              </Gt>  

          </And>  

            </Where>";

        }

    }

 

 

 

你可能感兴趣的:(view)