thyking xiao's blog

远行者需要智慧,更需要耐心! 工欲善其事,必先利其器。 授之鱼,不如授之渔。

博客园 首页 新随笔 联系 订阅 管理
  24 Posts :: 5 Stories :: 41 Comments :: 3 Trackbacks

2008年7月12日 #

在上一篇文章中基本上已实现了网站的多语言功能了,但是网站上的图片,CSS样式文件怎么利用资料文件来实现呢?

1.我们接着上一篇文章中建立的项目继续做,新建一个test2.aspx文件,同时新建一个images文件夹和style文件夹.
在images文件夹下放两张图片: loading.gif 和loading_en.gif  . 在style文件夹下建两个CSS样式表文件: CSS.css 和CSS_en.css

CSS.css文件的样式代码为:

body
{
    font-family: Arial @宋体 font-size:12px;
   
}

#maindiv
{
    margin: 20px;
    padding: 10px;
    height: 200px;
    width: 200px;
    border: solid 5px #C0C0C0;
    text-align: center;
    background-color: Olive;
}

CSS_en.css文件样式代码为:

body
{
    font-family: Arial Verdana;
    font-size: 12px;
}


#maindiv
{
    margin: 20px;
    padding: 10px;
    height: 200px;
    width: 200px;
    border: solid 5px #C0C0C0;
    text-align: center;
    background-color: gray;
}


2.新一个命名为BaseLanguage.cs的类,并设置这类继承: System.Web.UI.Page ,代码如下:


    public class BaseLanguage : System.Web.UI.Page
    {
        protected override void InitializeCulture()
        {
            string culture = Request.QueryString["curlanguage"];
            if (!String.IsNullOrEmpty(culture))
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
                System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(culture);
            }
        }

    }

因为上面的这段代码是每个页面都必须要有的,所以这里把分给写到一个专门的类中,并继承System.Web.UI.Page,然后每个页面再继承这个类就可以了

整个项目的文件结构如下图所示:



3.打开test2.aspx文件,在head中加入
<head runat="server">
    <title>asp.net 2.0实现多语言</title>
    
    <link href="style/CSS.css" rel="stylesheet" type="text/css" id="link"  runat="server"/>
   
</head>


这里我给<link>,添加了runat="server" id="link",就把link作为了一个服务器控件了,在后台可以引用
同时body中的代码如下:
<body>
    <form id="form1" runat="server">
   <center>
        <div id="maindiv">
            <br />
            <a href="?curlanguage=zh-cn">中文</a> &nbsp;
             <a href="?curlanguage=en-us">英文</a>
            <br />
            <br />
            国家:&nbsp;<asp:Literal ID="ltlcountry" runat="server"></asp:Literal>
            <br />
            城市:&nbsp;<asp:Literal ID="ltlcity" runat="server"></asp:Literal>
           
             <br />
            <br />
            国家2:&nbsp;<asp:Literal ID="ltlcountry2" runat="server"></asp:Literal>
            <br />
            城市2:&nbsp;<asp:Literal ID="ltlcity2" runat="server"></asp:Literal>
            <br />
            <br />
            <br />
            <br />
            <img runat="server" id="imgLoading" alt="" src="~/images/loading.gif" />
            
        </div>
    </center>
    </form>
</body>


//注意加个img标签,runat="server"

4.打开资源文件,添加一个名称为loadingImg和pagestyle的资源项:如下图所示





5. 打开test2.aspx.cs文件,把它继承"System.Web.UI.Page" 改成继承 "BaseLanguage"类
代码如下所示:


    public partial class Test2 : BaseLanguage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                link.Href = Resources.language.pagestyle.ToString();   //页面的样式文件设置
                imgLoading.Src = Resources.language.loadingImg.ToString();   //图片的路径

                ltlcountry.Text = Resources.language.country.ToString();
                ltlcity.Text = Resources.language.city.ToString();

                ltlcountry2.Text = (string)GetGlobalResourceObject("language", "country");
                ltlcity2.Text = (string)GetGlobalResourceObject("language", "city");

               

            }
        }
    }

6.build下整个项目,F5浏览下 test2.aspx 的 效果:图片和样式都有改变


7.最后 如何让我网站自动根据用户端的浏览器语言设置来自动显示相应的呢?
  1)打开web.config文件, 在system.web节中间加上globalization配置节,如下代码:
<system.web>
.......
<globalization culture="auto" uiCulture="auto" requestEncoding="UTF-8" responseEncoding="UTF-8"/>
    </system.web>


   2)打开IE浏览器,工具-->Internet选项-->常规-->语言  ,来设置浏览器的语言项,为里我把英语(美国)移到最上面 .如下图所示:



点"确定",关了浏览器,然后再重新浏览 test2.aspx.在我们没有点击"英文"就自动显示英文了.



整个项目的源文件下载: 
/Files/xiaoxijin/MulitLanguage.rar



posted @ 2008-07-12 11:56 thyking xiao 阅读(256) | 评论 (1)编辑

1.新建一个asp.net web应用程序


2.创建的项目如下图所示


3.右击web项目名称,添加一个全局资源文件夹"app_GlobalResources" ,这个是asp.net 2.0特有的


4.右击"app_GlobalResources"文件夹,添加两个资源文件: language.resx(简体资源文件)  和language.en-us.resx (英文的资源文件)




5.打开两个资源文件,添加相应的资源信息,如下图所示




6.打开default.aspx文件,输入如下代码:
<body>
    <form id="form1" runat="server">
    <center>
        <div style="margin: 20px; padding: 10px; height: 200px; width: 200px; border: solid 1px #C0C0C0;
            text-align: center;">
            <br />
            <a href="?curlanguage=zh-cn">中文</a> &nbsp;
             <a href="?curlanguage=en-us">英文</a>
            <br />
            <br />
            国家:&nbsp;<asp:Literal ID="ltlcountry" runat="server"></asp:Literal>
            <br />
            城市:&nbsp;<asp:Literal ID="ltlcity" runat="server"></asp:Literal>
           
             <br />
            <br />
            国家2:&nbsp;<asp:Literal ID="ltlcountry2" runat="server"></asp:Literal>
            <br />
            城市2:&nbsp;<asp:Literal ID="ltlcity2" runat="server"></asp:Literal>
        </div>
    </center>
    </form>
</body>


预览如下图所示:


7.打开Default.aspx.cs文件,输入如下代码:

  

//这段代码很重要 
protected override void InitializeCulture()
        {
            string culture = Request.QueryString["curlanguage"];
            if (!String.IsNullOrEmpty(culture))
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
                System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(culture);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ltlcountry.Text = Resources.language.country.ToString();
                ltlcity.Text = Resources.language.city.ToString();

                ltlcountry2.Text =(string)GetGlobalResourceObject("language", "country");
                ltlcity2.Text=(string)GetGlobalResourceObject("language", "city");

            }
        }

8. build下整个项目,按F5浏览: 点击下图中的  "中文" 和 "英文" 链接就可以查看我们所要的效果了









posted @ 2008-07-12 10:41 thyking xiao 阅读(131) | 评论 (1)编辑

2008年3月23日 #

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;

//如果是单独放在一个类中,记得要引用System.Web.Extensions,否则 ScriptManager不能用


namespace THYKING.Common
{
    public class Script
    {
        public Script()
        {

        }

        /// <summary>
        /// Ajax弹出消息
        /// </summary>
        /// <param name="message">弹出消息</param>
        /// <param name="control">控件名称(UpdatePanel,在User Control(*.ascx)中用this)</param>
        public static void AjaxAlert(string message,Control control)
        {
            ScriptManager.RegisterStartupScript(control,control.GetType(),null,"alert('"+message+"');",true);
        }


        /// <summary>
        ///  Ajax弹出消息后,跳转到另一个页面(同一个窗口),如果要跳转的页面是当前页面,则刷新当前页面
        /// </summary>
        /// <param name="message">弹出消息</param>
        /// <param name="gopage">要跳转到的页面(test.aspx)</param>
        /// <param name="control">控件名称(UpdatePanel,在User Control(*.ascx)中用this)</param>
        public static void AjaxAlertGoPage(string message, string gopage, Control control)
        {
            string strScript = "alert('" + message + "');window.window.location.href='" + gopage + "';";
            ScriptManager.RegisterStartupScript(control, control.GetType(), null, strScript, true);
        }


        /// <summary>
        /// 向页面注册javascript
        /// </summary>
        /// <param name="strScript">javascript语句</param>
        /// <param name="control">控件名称(UpdatePanel,在User Control(*.ascx)中用this)</param>
        public static void AjaxRegisterScript(string strScript, Control control)
        {

            ScriptManager.RegisterStartupScript(control, control.GetType(), null, strScript , true);    

        }


        /// <summary>
        /// alert弹出消息
        /// </summary>
        /// <param name="message">弹出消息</param>
        /// <param name="page">this</param>
        public static void Alert(string message, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), null, "alert('" + message + "');", true);
           
        }

        /// <summary>
        /// alert弹出消息后,跳转到另一个页面(同一个窗口),如果要跳转的页面是当前页面,则刷新当前页面
        /// </summary>
        /// <param name="message">弹出消息</param>
        /// <param name="gopage">要跳转到的页面(test.aspx)</param>
        /// <param name="page">this</param>
        public static void AlertGoPage(string message, string gopage, Page page)
        {
            string strScript = "alert('" + message + "');window.window.location.href='" + gopage + "';";
            page.ClientScript.RegisterStartupScript(page.GetType(), null, strScript, true);
        }


        /// <summary>
        /// 向页面注册javascript
        /// </summary>
        /// <param name="strScript">javascript语句</param>
        /// <param name="page">this</param>
        public static void RegisterScript(string strScript, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), null, strScript, true);

        }


    }
}

posted @ 2008-03-23 00:18 thyking xiao 阅读(261) | 评论 (0)编辑

2008年1月24日 #

06年做的一个很小的web程序,vs.net 2005 + ACCESS数据库开发
/Files/xiaoxijin/WebSite.rar
posted @ 2008-01-24 22:18 thyking xiao 阅读(70) | 评论 (0)编辑

2008年1月4日 #

注: 來自:http://www.cnsdn.com.cn/inc/show.asp?id=1012
//关闭,父窗口弹出对话框,子窗口直接关闭
this.Response.Write("<script language=javascript>window.close();</script>");

//关闭,父窗口和子窗口都不弹出对话框,直接关闭
this.Response.Write("<script>");
this.Response.Write("{top.opener =null;top.close();}");
this.Response.Write("</script>");

//弹出窗口刷新当前页面width=200 height=200菜单。菜单栏,工具条,地址栏,状态栏全没有
this.Response.Write("<script language=javascript>window.open('rows.aspx','newwindow','width=200,height=200')</script>");

//弹出窗口刷新当前页面
this.Response.Write("<script language=javascript>window.open('rows.aspx')</script>");
this.Response.Write("<script>window.open('WebForm2.aspx','_blank');</script>");

//弹出提示窗口跳到webform2.aspx页(在一个IE窗口中)
this.Response.Write(" <script language=javascript>alert('注册成功');window.window.location.href='WebForm2.aspx';</script> ");

//关闭当前子窗口,刷新父窗口
this.Response.Write("<script>window.opener.location.href=window.opener.location.href;window.close();</script>");
this.Response.Write("<script>window.opener.location.replace(window.opener.document.referrer);window.close();</script>");

//子窗口刷新父窗口
this.Response.Write("<script>window.opener.location.href=window.opener.location.href;</script>");
this.Response.Write("<script>window.opener.location.href='WebForm1.aspx';</script>");

//弹出提示窗口.确定后弹出子窗口(WebForm2.aspx)
this.Response.Write("<script language='javascript'>alert('发表成功!');window.open('WebForm2.aspx')</script>");

//弹出提示窗口,确定后,刷新父窗口
this.Response.Write("<script>alert('发表成功!');window.opener.location.href=window.opener.location.href;</script>");

//弹出相同的一页
<INPUT type="button" value="Button" onclick="javascript:window.open(window.location.href)">

//
Response.Write("parent.mainFrameBottom.location.href='yourwebform.aspx?temp=" +str+"';");


<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no') //这句要写成一行
-->
</SCRIPT> 
  
  参数解释:
  
  <SCRIPT LANGUAGE="javascript"> js脚本开始;
  window.open 弹出新窗口的命令;
  'page.html' 弹出窗口的文件名;
  'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替;
  height=100 窗口高度;
  width=400 窗口宽度;
  top=0 窗口距离屏幕上方的象素值;
  left=0 窗口距离屏幕左侧的象素值;
  toolbar=no 是否显示工具栏,yes为显示;
  menubar,scrollbars 表示菜单栏和滚动栏。
  resizable=no 是否允许改变窗口大小,yes为允许;
  location=no 是否显示地址栏,yes为允许;
  status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
  </SCRIPT> js脚本结束

'newwin':隐藏菜单栏地址栏工具条
width=50:宽度
height=50:高度
scrollbars=yes/no:滚动条
top=50:窗口距离屏幕上方
left=50:窗口距离屏幕左侧
例:window.open('detail.aspx?ID="+e.Item.Cells[1].Text+"','newwin','width=750,height=600,scrollbars=yes,top=50,left=50');");
this.Response.Write("<Script>window.open('WebForm2.aspx','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=750,height=470,left=80,top=40');</script>");

例:
this.Response.Write("<script>alert('发表成功!');window.opener.location.href=window.opener.location.href;</script>");
this.Response.Write("<script>");
this.Response.Write("{top.opener =null;top.close();}");
this.Response.Write("</script>");

例: linkcolumn1.DataNavigateUrlFormatString="javascript:varwin=window.open('edit_usr.aspx?actid={0}','newwin','width=750,height=600,scrollbars=yes,top=50,left=50');window.close()";

this.Response.Write("<Script>window.open('WebForm7.aspx','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=750,height=470,left=80,top=40');</script>");

弹出跟你当前的窗口有没有菜单工具栏没有关系,你只要在页面中写一个脚本它就弹出了.比如
<a href=# onclick="window.open('xxx.aspx','窗口名称','参数');">xxxxx</a>

以下列出一些弹出窗口的参数,你可自行设定,参数之间用逗号分隔

可选。字符串--列出对象表并用逗号分开。每一项都有自己的值,他们将被分开(如:"fullscreen=yes, toolbar=yes")。下面是被支持的各种特性。 
channelmode = { yes | no | 1 | 0 } 是否在窗口中显示阶梯模式。默认为no。
directories = { yes | no | 1 | 0 } 是否在窗口中显示各种按钮。默认为yes。
fullscreen = { yes | no | 1 | 0 } 是否用全屏方式显示浏览器。默认为no。使用这一特性时需要非常小心。因为这一属性可能会隐藏浏览器的标题栏和菜单,你必须提供一个按钮或者其他提示来帮助使用者关闭这一浏览窗口。ALT+F4可以关闭窗口。一个全屏窗口必须使用阶梯(channelmode)模式。
height = number 指定窗口的高度,单位是像素。最小值是100。
left = number 指定窗口距左边框的距离,单位是像素。值必须大于或者等于0。
location = { yes | no | 1 | 0 } 指定是否在窗口中显示地址栏。默认为yes。
menubar = { yes | no | 1 | 0 } 指定是否在窗口中显示菜单栏。默认为yes。
resizable = { yes | no | 1 | 0 } 指定是否在窗口中显示可供用户调整大小的句柄。默认为yes。
scrollbars = { yes | no | 1 | 0 } 指定是否在窗口中显示横向或者纵向滚动条。默认为yes。
status = { yes | no | 1 | 0 } 指定是否在窗口中显示状态栏。默认为yes。
titlebar = { yes | no | 1 | 0 } 指定是否在窗口中显示标题栏。在非调用HTML Application或者一个对话框的情况下,这一项将被忽略。默认为yes。
toolbar = { yes | no | 1 | 0 } 指定是否在窗口中显示工具栏,包括如前进、后退、停止等按钮。默认为yes。
top = number 指定窗口顶部的位置,单位是像素。值必须大于或者等于0。
width = number 指定窗口的宽度,单位是像素。最小值是100。

【1、最基本的弹出窗口代码】
  
  <SCRIPT LANGUAGE="javascript">
  <!--
  window.open ('page.html')
  -->
  </SCRIPT>
  
  因为这是一段javascripts代码,所以它们应该放在<SCRIPT LANGUAGE="javascript">标签和</script>之间。<!-- 和 -->是对一些版本低的浏览器起作用,在这些老浏览器中不会将标签中的代码作为文本显示出来。要养成这个好习惯啊。window.open ('page.html') 用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。用单引号和双引号都可以,只是不要混用。这一段代码可以加入HTML的任意位置,<head>和</head>之间可以,<body>间</body>也可以,越前越早执行,尤其是页面代码长,又想使页面早点弹出就尽量往前放。
  
【2、经过设置后的弹出窗口】
  
  下面再说一说弹出窗口的设置。只要再往上面的代码中加一点东西就可以了。我们来定制这个弹出的窗口的外观,尺寸大小,弹出的位置以适应该页面的具体情况。
  
  <SCRIPT LANGUAGE="javascript">
  <!--
  window.open ('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no') //这句要写成一行
  -->
  </SCRIPT> 
  
  参数解释:
  
  <SCRIPT LANGUAGE="javascript"> js脚本开始;
  window.open 弹出新窗口的命令;
  'page.html' 弹出窗口的文件名;
  'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替;
  height=100 窗口高度;
  width=400 窗口宽度;
  top=0 窗口距离屏幕上方的象素值;
  left=0 窗口距离屏幕左侧的象素值;
  toolbar=no 是否显示工具栏,yes为显示;
  menubar,scrollbars 表示菜单栏和滚动栏。
  resizable=no 是否允许改变窗口大小,yes为允许;
  location=no 是否显示地址栏,yes为允许;
  status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
  </SCRIPT> js脚本结束
    
【3、用函数控制弹出窗口】
  
  下面是一个完整的代码。
  <html>
  <head>
  <script LANGUAGE="JavaScript">
  <!--
  function openwin() {
  window.open ("page.html", "newwindow", "height=100, width=400, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //写成一行
  }
  //-->
  </script>
  </head>
  <body onload="openwin()">
  任意的页面内容...
  </body>
  </html>

  这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。怎么调用呢?

  方法一:<body onload="openwin()"> 浏览器读页面时弹出窗口;
  方法二:<body onunload="openwin()"> 浏览器离开页面时弹出窗口;
  方法三:用一个连接调用:
  <a href="#" onclick="openwin()">打开一个窗口</a>
  注意:使用的“#”是虚连接。
  方法四:用一个按钮调用:
  <input type="button" onclick="openwin()" value="打开窗口">
   
【4、同时弹出2个窗口】
  
   对源代码稍微改动一下:
  
  <script LANGUAGE="JavaScript">
  <!--
  function openwin() {
  window.open ("page.html", "newwindow", "height=100, width=100, top=0, left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=n o, status=no")//写成一行
  window.open ("page2.html", "newwindow2", "height=100, width=100, top=1 00, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, loca tion=no, status=no")//写成一行
  }
  //-->
  </script>
  为避免弹出的2个窗口覆盖,用top和left控制一下弹出的位置不要相互覆盖即可 。最后用上面说过的四种方法调用即可。
  注意:2个窗口的name(newwindows和newwindow2)不要相同,或者干脆全部为空。 
 
【5、主窗口打开文件1.htm,同时弹出小窗口page.html】

  如下代码加入主窗口<head>区:
  <script language="javascript">
  <!--
  function openwin() {
  window.open("page.html","","width=200,height=200")
  }
  //-->
  </script>
  加入<body>区:
  <a href="1.htm" onclick="openwin()">open</a>即可。
  
【6、弹出的窗口之定时关闭控制】
  
  下面我们再对弹出的窗口进行一些控制,效果就更好了。如果我们再将一小段 代码加入弹出的页面(注意是加入page.html的HTML中,不是主页面中),让它10秒后自动关闭是不是更酷了?
首先,将如下代码加入page.html文件的<head>区:
  <script language="JavaScript">
  function closeit()
  {
  setTimeout("self.close()",10000) //毫秒
  }
  </script>
  然后,再用<body onload="closeit()"> 这一句话代替page.html中原有的<BODY>这一句就可以了。(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。)

【7、在弹出窗口中加上一个关闭按钮】

  <FORM>
  <INPUT TYPE='BUTTON' VALUE='关闭' onClick='window.close()'>
  </FORM>
  呵呵,现在更加完美了!

【8、内包含的弹出窗口-一个页面两个窗口】

  上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。通过下面的例子,你可以在一个页面内完成上面的效果。

  <html>
  <head>
  <SCRIPT LANGUAGE="JavaScript">
  function openwin()
  {
  OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no ,scrollbars="+scroll+",menubar=no");
  //写成一行
  OpenWindow.document.write("<TITLE>例子</TITLE>")
  OpenWindow.document.write("<BODY BGCOLOR=#ffffff>")
  OpenWindow.document.write("<h1>Hello!</h1>")
  OpenWindow.document.write("New window opened!")
  OpenWindow.document.write("</BODY>")
  OpenWindow.document.write("</HTML>")
  OpenWindow.document.close()
  }
  </SCRIPT>
  </head>
  <body>
  <a href="#" onclick="openwin()">打开一个窗口</a>
  <input type="button" onclick="openwin()" value="打开窗口">
  </body>
  </html>

  看看OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照格式写更多的行即可。千万注意多一个标签或少一个标签就会出现错误。记得用 OpenWindow.document.close()结束啊。

【9、终极应用--弹出的窗口之Cookie控制】

  回想一下,上面的弹出窗口虽然酷,但是有一点小毛病,比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,我们使用cookie来控制一下就可以了。
  首先,将如下代码加入主页面HTML的<HEAD>区:

  <script>
  function openwin(){
  window.open("page.html","","width=200,height=200")
  }
  function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
  offset = document.cookie.indexOf(search)
  if (offset != -1) {
  offset += search.length
  end = document.cookie.indexOf(";", offset);
  if (end == -1)
  end = document.cookie.length;
  returnvalue=unescape(document.cookie.substring(offset, end))
  }
  }
  return returnvalue;
  }  
  function loadpopup(){
  if (get_cookie('popped')==''){
  openwin()
  document.cookie="popped=yes"
  }
  }
  </script>

  然后,用<body onload="loadpopup()">(注意不是openwin而是loadpop啊!)替换主页面中原有的<BODY>这一句即可。你可以试着刷新一下这个页面或重新进入该页面,窗口再也不会弹出了。真正的Pop-Only-Once!

posted @ 2008-01-04 15:06 thyking xiao 阅读(133) | 评论 (0)编辑

2007年12月28日 #

a.aspx 文件中的代码:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>gridview控件示例</title>
   
    <link href="App_Themes/Theme1/index.css" rel="stylesheet" type="text/css" />
   
 <script type="text/javascript" language="javascript">
      
    function DoCheck(flag)// 全选 flag=1 反选 flag=0
    {
        var inputs = document.forms[0].elements;
        for (var i=0; i < inputs.length; i++)
        if (inputs[i].type == 'checkbox')
        {
            if (flag)
                inputs[i].checked = true;
           else
                inputs[i].checked =!inputs[i].checked;
        }
    }
     
   
</script>
</head>
<body >    

    <form id="form1" runat="server">
<asp:GridView id="gvMyDeptNotFinished" runat="server" OnPageIndexChanging="gvMyDeptNotFinished_PageIndexChanging" AllowPaging="True" AutoGenerateColumns="False" SkinID="gvcaselist">
<Columns>
 <asp:TemplateField Visible="false" >              
<ControlStyle Width="20px"  />
 <HeaderTemplate>    
 <a onclick="DoCheck(0);" href="#">反选</a> <%--反选--%>
 <a onclick="DoCheck(1);" href="#">全选</a> <%--全选--%>                  
</HeaderTemplate>
<ItemTemplate>
<div style="text-align:center;width:50px;">
    <asp:CheckBox ID="CheckBox1" runat="server"/>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" Visible="false" >
<ControlStyle Width="0px" />
<ItemTemplate>
    <asp:Label ID="lblID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="姓名">
<ControlStyle Width="100px"></ControlStyle>
<ItemTemplate>
<div style="text-align:left; padding-left:5px;">
<a href='<%# "MyDeptNotFinishedDetails.aspx?emp_code="+Eval("emp_code")+"&titleid="+Request.QueryString["titleid"]+"&cur_status="+Request.QueryString["cur_status"]%>' target="_self" class="nav2"><%# Eval("pic_cn")%></a>

</div><%--这里参数从前一页传过来的,也有从数据绑定的,要注意不要写错了哦--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="数量">
<ControlStyle Width="150px"></ControlStyle>
<ItemTemplate>
  <div class="myclass1">
   <asp:Literal ID="litcasesum" runat="server" Text='<%# Eval("sumcase") %>'></asp:Literal>                              
   </div>               
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="点数">
<ControlStyle Width="150px"></ControlStyle>
<ItemTemplate>
  <div style="text-align:left; color:Red ;">
   <asp:Literal ID="litScore" runat="server" Text='<%# Eval("CaseWeight") %>'></asp:Literal>                             </div>               
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="当前操作人">
<ControlStyle Width="100px"></ControlStyle>
<ItemTemplate>
  <div style="text-align:left;">
   <%# Eval("operator") %>                              
   </div>               
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="当前状态">
<ControlStyle Width="250px"></ControlStyle>
<ItemTemplate>
<asp:Label ID="lblcasename" runat="server" Text='<%# Eval("cur_status_name") %>'  ></asp:Label>             
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<DIV class="gvbottom">&nbsp;
<asp:Button id="btnGoToBack" onclick="btnGoToBack_Click" runat="server" Text="返回" SkinID="loginbtn"></asp:Button> &nbsp;
<asp:Button id="btnToConfirm" runat="server" Text="确认" OnClientClick="javascript:return confirm('确认选择?')" SkinID="loginbtn" OnClick="btnToConfirm_Click" ></asp:Button>
</DIV>
</form>
</body>

</html>


===========

.aspx.cs文件代码


 // using System.Data.SqlClient;

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetMyDeptNotFinishedCase();
        }
    }


/// <summary>
    /// gridview數據綁定
    /// </summary>
    private void GetMyDeptNotFinishedCase()
    {
        DataSet ds = new DataSet();
        ds = bll.RunProcedure("CP_MyDeptNotFinished_Person");
        if (ds.Tables[0].Rows.Count > 0)
        {
            gvMyDeptNotFinished.DataSource = ds.Tables[0];
            gvMyDeptNotFinished.DataBind();
        }
        else
        {
         //Response.Write("取数据出错,或没有记录");
        }

    }


   /// <summary>
    /// 确认 button 按钮事件
    /// </summary>
    /// <returns></returns>
protected void btnToConfirm_Click(object sender, EventArgs e)
    {
 
        string allselect = GetSelected();
        if (string.IsNullOrEmpty(allselect))
        {
            //Response.Write("您还没有选择数据,请至少选择一项!");
            return;
        }

        string[] allempcode = allselect.Split(',');

        int rowsAffected = 0;       
        
        foreach (string emp_code in allempcode)
        {
           
            try
            {
                SqlParameter[] parameters ={
                                        new SqlParameter("@emp_code",SqlDbType.NVarChar)
                                        };
                parameters[0].Value = emp_code;
              

                bll.RunProcedure("CP_Help", parameters, out rowsAffected); //使用存储过程
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message);

            }
        }

        if (rowsAffected > 0)
        {
               //Response.Write("操作成功!");
               
        }
        else
        {
            //Response.Write("操作失败!");
            Return;
        }

       GetMyDeptNotFinishedCase();//重新再绑定数据到gridview控件


   }


   /// <summary>
    /// 取所有已被選擇項的ID值,
    /// </summary>
    /// <returns></returns>

 private string GetSelected()
    {
        string emp_code = null;
        foreach (GridViewRow gvrow in gvMyDeptNotFinished.Rows)
        {
            CheckBox ch = (CheckBox)gvrow.Cells[0].FindControl("CheckBox1");
            if (ch.Checked)
            {
                Label lbl = (Label)gvrow.Cells[1].FindControl("lblID");
                emp_code += lbl.Text + ",";               
            }
        }

        if (!string.IsNullOrEmpty(emp_code))
        {
            emp_code = emp_code.Substring(0, emp_code.Length - 1);
        }
        return emp_code;
    }


 /// <summary>
    /// 返回按鈕事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnGoToBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("MyDeptNotFinished.aspx?titleid="+Request.QueryString["titleid"].ToString());
   
   
    }


另外,我们在数据绑定到gridview控件,有时需要把一项的单个值特别显示出来,比如使用不同的颜色
如下图所示:(申请了变更)

其实这样也很容易实现的,只要我们改下SQL查询语句就可以做到的:
SQL:
SELECT         ID, case_name, ctrl_proc, CONVERT(nvarchar(20), updatedate, 111)
                          AS updatedate,
CaseWeight, 
                          CASE is_apply WHEN '1' THEN '<font color=red>是</font>' ELSE '否' END AS is_apply
FROM             mytable

  



 


posted @ 2007-12-28 19:32 thyking xiao 阅读(364) | 评论 (0)编辑

2007年9月29日 #

下列语句部分是Mssql语句,不可以在access中使用。

SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)

首先,简要介绍基础语句:
1、说明:创建数据库
CREATE DATABASE database-name
2、说明:删除数据库
drop database dbname
3、说明:备份sql server
--- 创建 备份数据的 device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- 开始 备份
BACKUP DATABASE pubs TO testBack
4、说明:创建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根据已有的表创建新表:
A:create table tab_new like tab_old (使用旧表创建新表)
B:create table tab_new as select col1,col2… from tab_old definition only
5、说明:删除新表drop table tabname
6、说明:增加一个列
Alter table tabname add column col type
注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。
7、说明:添加主键: Alter table tabname add primary key(col)
说明:删除主键: Alter table tabname drop primary key(col)
8、说明:创建索引:create [unique] index idxname on tabname(col….)
删除索引:drop index idxname
注:索引是不可更改的,想更改必须删除重新建。
9、说明:创建视图:create view viewname as select statement
删除视图:drop view viewname
10、说明:几个简单的基本的sql语句
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’ ---like的语法很精妙,查资料!
排序:select * from table1 order by field1,field2 [desc]
总数:select count * as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
11、说明:几个高级查询运算词
A: UNION 运算符
UNION 运算符通过组合其他两个结果表(例如 TABLE1 和 TABLE2)并消去表中任何重复行而派生出一个结果表。当 ALL 随 UNION 一起使用时(即 UNION ALL),不消除重复行。两种情况下,派生表的每一行不是来自 TABLE1 就是来自 TABLE2。
B: EXCEPT 运算符
EXCEPT 运算符通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表。当 ALL 随 EXCEPT 一起使用时 (EXCEPT ALL),不消除重复行。
C: INTERSECT 运算符
INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。当 ALL 随 INTERSECT 一起使用时 (INTERSECT ALL),不消除重复行。
注:使用运算词的几个查询结果行必须是一致的。
12、说明:使用外连接
A、left outer join:
左外连接(左连接):结果集几包括连接表的匹配行,也包括左连接表的所有行。
SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
B:right outer join:
右外连接(右连接):结果集既包括连接表的匹配连接行,也包括右连接表的所有行。
C:full outer join:
全外连接:不仅包括符号连接表的匹配行,还包括两个连接表中的所有记录。

其次,大家来看一些不错的sql语句
1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)
法一:select * into b from a where 1<>1
法二:select top 0 * into b from a

2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)
insert into b(a, b, c) select d,e,f from b;

3、说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)
insert into b(a, b, c) select d,e,f from b in ‘具体数据库’ where 条件
例子:..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..

4、说明:子查询(表名1:a 表名2:b)
select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)

5、说明:显示文章、提交人和最后回复时间
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b

6、说明:外连接查询(表名1:a 表名2:b)
select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c

7、说明:在线视图查询(表名1:a )
select * from (SELECT a,b,c FROM a) T where t.a > 1;

8、说明:between的用法,between限制查询数据范围时包括了边界值,not between不包括
select * from table1 where time between time1 and time2
select a,b,c, from table1 where a not between 数值1 and 数值2

9、说明:in 的使用方法
select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)

10、说明:两张关联表,删除主表中已经在副表中没有的信息
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

11、说明:四表联查问题:
select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....

12、说明:日程安排提前五分钟提醒
SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())>5

13、说明:一条sql 语句搞定数据库分页
select top 10 b.* from (select top 20 主键字段,排序字段 from 表名 order by 排序字段 desc) a,表名 b where b.主键字段 = a.主键字段 order by a.排序字段

14、说明:前10条记录
select top 10 * form table1 where 范围

15、说明:选择在每一组b值相同的数据中对应的a最大的记录的所有信息(类似这样的用法可以用于论坛每月排行榜,每月热销产品分析,按科目成绩排名,等等.)
select a,b,c from tablename ta where a=(select max(a) from tablename tb where tb.b=ta.b)

16、说明:包括所有在 TableA 中但不在 TableB和TableC 中的行并消除所有重复行而派生出一个结果表
(select a from tableA ) except (select a from tableB) except (select a from tableC)

17、说明:随机取出10条数据
select top 10 * from tablename order by newid()

18、说明:随机选择记录
select newid()

19、说明:删除重复记录
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)

20、说明:列出数据库里所有的表名
select name from sysobjects where type='U'

21、说明:列出表里的所有的
select name from syscolumns where id=object_id('TableName')

22、说明:列示type、vender、pcs字段,以type字段排列,case可以方便地实现多重选择,类似select 中的case。
select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C' then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename group by type
显示结果:
type vender pcs
电脑 A 1
电脑 A 1
光盘 B 2
光盘 A 2
手机 B 3
手机 C 3

23、说明:初始化表table1
TRUNCATE TABLE table1

24、说明:选择从10到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc
  
随机选择数据库记录的方法(使用Randomize函数,通过SQL语句实现)
  对存储在数据库中的数据来说,随机数特性能给出上面的效果,但它们可能太慢了些。你不能要求ASP“找个随机数”然后打印出来。实际上常见的解决方案是建立如下所示的循环:
Randomize
RNumber = Int(Rnd*499) +1
 
While Not objRec.EOF
If objRec("ID") = RNumber THEN
... 这里是执行脚本 ...
end if
objRec.MoveNext
Wend
 
  这很容易理解。首先,你取出1到500范围之内的一个随机数(假设500就是数据库内记录的总数)。然后,你遍历每一记录来测试ID 的值、检查其是否匹配RNumber。满足条件的话就执行由THEN 关键字开始的那一块代码。假如你的RNumber 等于495,那么要循环一遍数据库花的时间可就长了。虽然500这个数字看起来大了些,但相比更为稳固的企业解决方案这还是个小型数据库了,后者通常在一个数据库内就包含了成千上万条记录。这时候不就死定了?
  采用SQL,你就可以很快地找出准确的记录并且打开一个只包含该记录的recordset,如下所示:
Randomize
RNumber = Int(Rnd*499) + 1
 
SQL = "SELECT * FROM Customers WHERE ID = " & RNumber
 
set objRec = ObjConn.Execute(SQL)
Response.WriteRNumber & " = " & objRec("ID") & " " & objRec("c_email")
 
  不必写出RNumber 和ID,你只需要检查匹配情况即可。只要你对以上代码的工作满意,你自可按需操作“随机”记录。Recordset没有包含其他内容,因此你很快就能找到你需要的记录这样就大大降低了处理时间。
再谈随机数
  现在你下定决心要榨干Random 函数的最后一滴油,那么你可能会一次取出多条随机记录或者想采用一定随机范围内的记录。把上面的标准Random 示例扩展一下就可以用SQL应对上面两种情况了。
  为了取出几条随机选择的记录并存放在同一recordset内,你可以存储三个随机数,然后查询数据库获得匹配这些数字的记录:
SQL = "SELECT * FROM Customers WHERE ID = " & RNumber & " OR ID = " & RNumber2 & " OR ID = " & RNumber3
 
  假如你想选出10条记录(也许是每次页面装载时的10条链接的列表),你可以用BETWEEN 或者数学等式选出第一条记录和适当数量的递增记录。这一操作可以通过好几种方式来完成,但是 SELECT 语句只显示一种可能(这里的ID 是自动生成的号码):
SQL = "SELECT * FROM Customers WHERE ID BETWEEN " & RNumber & " AND " & RNumber & "+ 9"

  注意:以上代码的执行目的不是检查数据库内是否有9条并发记录。

 
随机读取若干条记录,测试过
Access语法:SELECT top 10 * From 表名 ORDER BY Rnd(id)
Sql server:select top n * from 表名 order by newid()
mysqlelect * From 表名 Order By rand() Limit n
Access左连接语法(最近开发要用左连接,Access帮助什么都没有,网上没有Access的SQL说明,只有自己测试, 现在记下以备后查)
语法elect table1.fd1,table1,fd2,table2.fd2 From table1 left join table2 on table1.fd1,table2.fd1 where ...
使用SQL语句 用...代替过长的字符串显示
语法:
SQL数据库:select case when len(field)>10 then left(field,10)+'...' else field end as news_name,news_id from tablename
Access数据库:SELECT iif(len(field)>2,left(field,2)+'...',field) FROM tablename;
 
Conn.Execute说明
Execute方法
  该方法用于执行SQL语句。根据SQL语句执行后是否返回记录集,该方法的使用格式分为以下两种:
    1.执行SQL查询语句时,将返回查询得到的记录集。用法为:
    Set 对象变量名=连接对象.Execute("SQL 查询语言")
   Execute方法调用后,会自动创建记录集对象,并将查询结果存储在该记录对象中,通过Set方法,将记录集赋给指定的对象保存,以后对象变量就代表了该记录集对象。

    2.执行SQL的操作性语言时,没有记录集的返回。此时用法为:
    连接对象.Execute "SQL 操作性语句" [, RecordAffected][, Option]
      ·RecordAffected 为可选项,此出可放置一个变量,SQL语句执行后,所生效的记录数会自动保存到该变量中。通过访问该变量,就可知道SQL语句队多少条记录进行了操作。
      ·Option 可选项,该参数的取值通常为adCMDText,它用于告诉ADO,应该将Execute方法之后的第一个字符解释为命令文本。通过指定该参数,可使执行更高效。

·BeginTrans、RollbackTrans、CommitTrans方法
  这三个方法是连接对象提供的用于事务处理的方法。BeginTrans用于开始一个事物;RollbackTrans用于回滚事务;CommitTrans用于提交所有的事务处理结果,即确认事务的处理。
  事务处理可以将一组操作视为一个整体,只有全部语句都成功执行后,事务处理才算成功;若其中有一个语句执行失败,则整个处理就算失败,并恢复到处里前的状态。
  BeginTrans和CommitTrans用于标记事务的开始和结束,在这两个之间的语句,就是作为事务处理的语句。判断事务处理是否成功,可通过连接对象的Error集合来实现,若Error集合的成员个数不为0,则说明有错误发生,事务处理失败。Error集合中的每一个Error对象,代表一个错误信息。

posted @ 2007-09-29 13:19 thyking xiao 阅读(127) | 评论 (1)编辑

2007年9月28日 #


button样式:
<asp:Button  SkinId="loginbtn" runat="server" Font-Size="12px"     BackColor="DimGray" BorderColor="Gray" BorderStyle="Inset" BorderWidth="1px" ForeColor="White" Width="50px" CssClass="btnlogin"  />

textbox样式:

    <asp:TextBox   runat="server" BackColor="WhiteSmoke" Font-Size="12px" Height="17px" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px" Width="120px"></asp:TextBox>


posted @ 2007-09-28 19:02 thyking xiao 阅读(439) | 评论 (0)编辑

下面是源码:
先添加js和CSS
<script type="text/javascript" language="javascript">
      
    function DoCheck(flag)// 全选 flag=1 反选 flag=0
    {
        var inputs = document.forms[0].elements;
        for (var i=0; i < inputs.length; i++)
        if (inputs[i].type == 'checkbox')
        {
            if (flag)
                inputs[i].checked = true;
           else
                inputs[i].checked =!inputs[i].checked;
        }
    }
</script>

CSS:
.ellipsis_row { OVERFLOW: hidden; WIDTH: 300px; WHITE-SPACE: nowrap;  TEXT-OVERFLOW: ellipsis; }
.caseweight{OVERFLOW: hidden; WIDTH: 20px; WHITE-SPACE: nowrap; color:Red ;text-align:center ;padding-left:10px;}


-----------------------------------------

gridview控件的设置如下:   其中OnRowDataBound="gvCaseList_RowDataBound" 事件中添加了光棒效果:

<asp:GridView ID="gvCaseList"   runat="server" AutoGenerateColumns="False" OnRowDataBound="gvCaseList_RowDataBound"  >
        <Columns>
       <asp:BoundField HeaderText="类型"  DataField="type" >
                <ControlStyle Width="80px" />
            </asp:BoundField>
                 <asp:TemplateField HeaderText="名称"> <!--把这一列转换为模板列-->                 
                <ControlStyle Width="300px" />
                <ItemTemplate>
                <DIV class="ellipsis_row"><%#DataBinder.Eval(Container.DataItem,"name")%></DIV> <!--这里使用了一个div,通过CSS来控制该列的宽度,多余的字符使用....表示-->                 
                </ItemTemplate>
            </asp:TemplateField>
                 <asp:TemplateField HeaderText="费用"> <!--把这一列转换为模板列-->                
              <ControlStyle Width="20px" />
                <ItemTemplate>
                <div class="caseweight"><%#DataBinder.Eval(Container.DataItem,"fee")%></div><!--把该列的数据用红色显示出来,改变了该的文字样式-->  
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField > <!--把这一列转换为模板列-->                
                <ControlStyle Width="20px"  />
                 <HeaderTemplate> <!--注意这个HeaderTemplate,在这里加了两链接用于全选和反选-->   
                 <a onclick="DoCheck(0);" href="#">反选</a> <!--反选-->
                 <a onclick="DoCheck(1);" href="#">全选</a> <!--全选-->                 
                </HeaderTemplate>
                <ItemTemplate>
                <div style="text-align:center ;">
                    <asp:CheckBox ID="CheckBox1" runat="server"/>
                </div>
                </ItemTemplate>
              
            </asp:TemplateField>
        </Columns>     
       
    </asp:GridView>

后台的光棒效果代码:(注意要添加OnRowDataBound="gvCaseList_RowDataBound"事件)

 protected void gvCaseList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF80'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");

        }

    }





posted @ 2007-09-28 18:48 thyking xiao 阅读(642) | 评论 (1)编辑

2007年6月17日 #


在asp.net 2.0中可以通过aspnet_regiis工具来进行连接字符串的加解密操作,若项目的名称是"myconfiguration",则代码如下:

加密:(asp.net 2.0)
aspnet_regiis -pe "connectionstrings" -app "/myconfiguration" -prov "RSAProtectedConfigurationProvider"

解密:
aspnet_regiis -pd "connectionstrings" -app "/myconfiguration"

其中:
-pe 指的是加密的web.config程序段
-app 指的是web应

用程序的虚拟目录
-prov 指的是选择哪能种加密方式的Provider
-pd 指的是解密web.config程序段




写了个.bat文件

解密字符串.bat

@echo off
echo 正在解密web.confing文件中的數據庫連接字符串 
cd c:\windows\microsoft.net\framework\v2.0.50727

rem 這個只能應用於asp.net2.0中,且數據庫連接字符串必須放在"connectionString"中,不能放在"appSettings"中
rem [注意] "/web" 請改為您自己的應用程序名稱(IIS中的應用程序),前面要記得加 "/"

aspnet_regiis -pd "connectionStrings" -app "/web"

echo 解密成功!
echo. & pause



加密字符串.bat

@echo off
echo 正在加密web.confing文件中的數據庫連接字符串 
cd c:\Windows\Microsoft.net\Framework\V2.0.50727

rem 這個只能應用於asp.net2.0中,且數據庫連接字符串必須放在"connectionString"中,不能放在"appSettings"中

rem [注意] "/iweb" 請改為您自己的應用程序名稱(IIS中的應用程序),前面要記得加 "/"

aspnet_regiis -pe "connectionStrings" -app "/web" -prov RSAProtectedConfigurationProvider

echo 加密成功!
echo. & pause












 

posted @ 2007-06-17 00:52 thyking xiao 阅读(395) | 评论 (0)编辑

2007年6月8日 #




<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="5" GridLines="Vertical" Width="100%" AllowPaging="True" PageSize="15">
            <Columns>
                <asp:BoundField DataField="t_id" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                    SortExpression="t_id" />
                <asp:BoundField DataField="t_date" HeaderText="日期" SortExpression="t_date" />
                <asp:TemplateField HeaderText="报案号" SortExpression="t_bah">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("t_bah") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                         <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ='<%# "../admin/update.aspx?id="+Eval("t_bah") %>'  Text='<%# Eval("t_bah") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="t_gh" HeaderText="调度员工号" SortExpression="t_gh" />
                <asp:BoundField DataField="t_name" HeaderText="查勘人" SortExpression="t_name" />
                <asp:BoundField DataField="t_time" HeaderText="时间" SortExpression="t_time" />
                <asp:BoundField DataField="t_qh" HeaderText="区域" SortExpression="t_qh" />
                <asp:BoundField DataField="t_ftime" HeaderText="反馈时间" SortExpression="t_ftime" />
                <asp:BoundField DataField="t_kf" HeaderText="扣分" SortExpression="t_kf" />
                <asp:BoundField DataField="t_bj" HeaderText="备注" SortExpression="t_bj" />
                <asp:TemplateField HeaderText="修改">
                    <ItemTemplate>
                        <asp:Button ID="Button1" runat="server" PostBackUrl='<%# "../admin/update.aspx?id="+Eval("t_bah")%>' CausesValidation="false" CommandName="Edit"
                            Text="修改" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="删除">
                    <ItemTemplate>
                        <asp:Button ID="Button2" runat="server" PostBackUrl ='<%# "../admin/dele.aspx?id="+Eval("t_bah") %>' CausesValidation="false" CommandName="Delete"
                            Text="删除" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle B