net 常用的传值方法

来源:互联网 发布:sftp 端口 编辑:程序博客网 时间:2024/05/16 16:22

*A.aspx 访问 B.aspx ,且A页面传递数据给B

1 request.Form["空间名称"] 方式接收

2 A.aspx 是用“B.aspx?a=1&b=c”方式传递给B.aspx 则在B页面使用Request.QueryString["a"] 方式接收

* A页面传值给A页面

ViewState[""]=value 传值,var =ViewState[""] 方式接收;

Hidden 控件.value=value 方式传值, var=hidden控件.value 方式接收

*A.aspx 不可以访问C.aspx,但是要求 A.aspx传值给 C.aspx

Application Session Cookie

Application 、Session 不用的时候,及时Remove();

HttpCookie obj = new HttpCookie("name","zhangdan")

obj.Expires = DateTime.Now.AddMinutes(2);//有效期 2分钟

HttpContext.Current.Response.AppendCookie(cookie);
调用:Request.Cookies["person_Users"]["U_IPinfo"];

//Request.Cookie.Add(obj);

cookie 对于单个网站 最多20 个

cookie 变量最多4kb的数据

 ***数据绑定 将检索到的数据连接到将显示该数据的控件的过程

DataBind() 是System.Web.UI.Control 的一个方法,并不是所有的控件都支持绑定<%#  ...%>

DataBind() 是后台绑定方法。

DataBinder.Evel(Container.DataItem,"Numbers") 是前台绑定

DataBinder.Evel() 用于计算运行时的数据绑定表达式,并按照浏览器的显示的要求来格式化输出,

有三个参数,1数据项目的命名容器,2数据字段名,3格式字符串

命名容器是针对其计算表达式的对象的一个引用:

Repeater、DataList、DataGrid,容器名是Container.DataItem

针对页面绑定 容器是Page

不使用格式化字符串的时候,DataBinder.Evel() 返回object类型的值

<%# Eval( "FileName ", "images/thumbs/{0} ") % >

<%# Eval( "PhotoID ", "PhotoFormViewPlain.aspx?ID={0} ") % >

<%# Eval( "Caption ") %>在cs里定义DGFormaSex(); protected string DGFormatSex(string xb){ if(xb == "1");

return "man";else return "false"} <%# num %> num 为共有 静态(尽量不用)变量,

显示二位小数< % DataGrid(Container.DataItem,"UnitPrice","${0:F2}")%>

{0:d}:转化类型 日期只显示年月日,{0:yyyy_mm_dd} 按格式显示年月日,{0;c} 货币样式

 

原创粉丝点击