ASP.NETÖÐCookieµÄ²Ù×÷
ÔÚѧϰ¹ý³ÌÖÐÐèÒªÓõ½CookieÎļþ£¬ÔÚÍøÉÏÕÒÁËЩÏà¹ØµÄ֪ʶ£¬Ñ§Ï°ÁËÒ»²¿·Ö£¬ÏּǼÈçÏ£º
£¨1£©
HttpCookie myHttpCookie = new HttpCookie("MyWebSite");
DateTime myDateTime = System.DateTime.Now;
TimeSpan myTimeSpan = new TimeSpan();
if (rbHour.Checked == true)
{
myTimeSpan = new TimeSpan(0, 1, 0, 0, 0);
myTime = 0;
}
if (rbDay.Checked == true)
{
myTimeSpan = new TimeSpan(1, 0, 0, 0, 0);
myTime = 1;
}
myHttpCookie.Expires = myDateTime.Add(myTimeSpan);
myHttpCookie.Values.Add("UserName", Server.HtmlEncode(txtUserName.Text.Trim().ToString()));
myHttpCookie.Values.Add("Sex", Server.HtmlEncode(mySex));
myHttpCookie.Values.Add("SelectTime", Server.HtmlEncode(myTime.ToString()));
Response.AppendCookie(myHttpCookie);
Õâ¶Î´úÂëµÄ×÷ÓÃÊÇ´´½¨Ò»¸öÃûΪMyWebSiteµÄCookieÎļþ£¬ÀïÃæÓÐÈýÏ·Ö±ðÊÇUserName£¨Óû§Ãû£©¡¢Sex£¨ÐԱ𣩺ÍSelectTime£¨CookieµÄ¹ýÆÚʱ¼ä£©¡£
£¨2£©
if (Request.Cookies["MyWebSite"] != null)
{
myUserName = Request.Cookies["MyWebSite"]["UserName"].ToString();
mySex = Request.Cookies["MyWebSite"]["Sex"].ToString();
myTime = Request.Cookies["MyWebSite"]["SelectTime"].ToString();
}
if (myUserName != null && mySex != null)
{
HttpCookie myHttpCookie = new HttpCookie("MyWebSite");
if (myHttpCookie != null)
{
myHttpCookie.Values["UserName"] = myUserName.ToString();
myHttpCookie.Values["Sex"] = mySex.ToString();
myHttpCookie.Values["SelectTime"] = myTime.ToString();
DateTime myDateTime=System.DateTime.Now;
if (myTime.ToString() == "0")
{
&nb
Ïà¹ØÎĵµ£º
Êý¾Ý°ó¶¨ÒÔ¼°Container.DataItemµÄ¾ßÌå·ÖÎö
Áé»îµÄÔËÓÃÊý¾Ý°ó¶¨²Ù×÷
°ó¶¨µ½¼òµ¥ÊôÐÔ:<%#UserName%>
°ó¶¨µ½¼¯ºÏ:<asp:ListBox id="ListBox1" datasource='<%# myArray%>' runat="server">
°ó¶¨µ½±í´ïʽ:<%#(class1.property1.ToString() + "," + class1.property2.ToString())%>
°ó¶¨µ½·½·¨·µ» ......
a. ReportViewer¹ØÁªReport1.rdlcµÄ¼òµ¥³ÊÏÖ
b. ¶Ô´øÓб¨±í²ÎÊýµÄReport1.rdlcµÄ³ÊÏÖ
c.
ÀûÓóÌʽÉú³ÉµÄDataSet Ìî³ä±¨±í
d. µ÷Óô洢¹ý³Ì Éú³ÉDataSet Ìî³ä±¨±í
==========
¼òµ¥µÄ³ÊÏÖ
==========
1. ´ò¿ªVS2005£¬Îļþ->н¨->ÍøÕ¾ Ñ¡ÔñÓïÑÔÖÖÀࣨC#£©
2. Ôڸýâ¾ö·½°¸ÏÂ
Éè¼ÆÆäÒѾÉú³ÉµÄDefault.aspx ......
ÔÚVisual StudioÖУ¬ËùÓеÄASP.NET 2.0¿Ø¼þ¶¼ÊÇ×Ô¶¨Òå¿Ø¼þ£¬´´½¨×Ô¼ºµÄ×Ô¶¨Òå¿Ø¼þÒ»°ãÐèÒªÍê³ÉÒÔÏÂÈý²½¡£
(1)ÔÚÕ¾µãAPP_CodeÏ´´½¨Ò»¸öÐÂÀࣻ
(2)ÐÞ¸ÄÕâ¸öÀ࣬ÈÃËü³ÉΪWebControlÀà(°üº¬ÔÚSystem.Web.UI.WebControlsÃüÃû¿Õ¼ä)µÄÅÉÉúÀࣻ
(3)ÖØд»ùÀà(¼´WebControlÀà)µÄRenderContents()·½·¨¡£
ÏÂÃæÊÇÒ»¸ö×î¼òµ¥µÄASP.NE ......
SQL:
using System.Data.SqlClient;
string sql = "server=.;uid=sa;pwd=;database=tablename;";
ACCESS:
using System.Data.OleDb;
string sql = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + HttpRuntime.AppDomainAppPath + "//App_Data//db.mdb";
HttpRuntime.AppDomainAppPath Ϊ¸ùĿ¼
......