mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
DotNET
DotNET

设置或者得到CheckBoxList选中了的值

在项目中我们可能会经常遇到一收集多选信息的情况,比如做注册的时候要收集个人爱好,那时候大家第一个想到的肯定是CheckBoxList。那我们怎么来获取到CheckBoxList的值并且存入数据库呢?? 如果我们还需要编辑用户的个人信息而其中爱好也是可以改动的,此时同样大家也会想用CheckBoxList去显示用户的各人信息,那我们又要如何将库里的值用CheckBoxList表示出来呢?? 编辑分析问题遇到这种情况大家肯定想到for,foreach去遍历,没错这样完没有问题,不管是获取CheckBoxList的值还是设置CheckBoxList的值我们都可以用遍历去实现。而我这里将大家常用的方法总结了一下,做了两个方法。这样用起来能更方便灵活。 举个例子:我们要收集某某公司员工的信息其中一项是爱好。而且要求员工信息可以改动 我们选用了CheckBoxList来实现爱好的收集和显示 方法: ...... 1.收集时,将CheckBoxList里选中的项转换成字符串,并用“,”隔开这里只要调用方法GetChecked(CheckBoxList checkList, string separator)就可以获取到想要的数据。然后存入数据库。 2.显示时,先从库里获取爱好的数据(刚刚用“,”隔开的字符串), 然后调用方法SetChecked(CheckBoxList checkList,string selval,string separator)就可以将库里的数据用CheckBoxList的形式表现出来 ......方法的使用: //这里获取CheckBoxList中的选中项并用","隔开string str=GetChecked(this.checkList1, ",");......//这里是将str这个字符串的值又设回CheckBoxListSetChecked(this.checkList1,str,",");         /// <summary>        /// 初始化CheckBoxList中哪些是选中了的        /// </summary>        /// <param name="cbl">CheckBoxList</param>        /// <param name="selectedValue">选中了的值串例如:"0,1,1,2,1"</param>        /// <param name="splitStr">值串中使用的分割符例如"0,1,1,2,1"中的逗号</param>        public static string SetCheckBoxList(CheckBoxList cbl, string selectedValue, string splitStr)        {            selectedValue = splitStr + selectedValue + splitStr;        //例如:"0,1,1,2,1"->",0,1,1,2,1,"            for (int i = 0; i < cbl.Items.Count; i++)            {                cbl.Items[i].Selected = false;                string val = splitStr + cbl.Items[i].Value + splitStr;                if (selectedValue.IndexOf(val) != -1)                {                    cbl.Items[i].Selected = true;                    selectedValue = selectedValue.Replace(val, splitStr);        //然后从原来的值串中删除已经选中了的                    if (selectedValue == splitStr)        //selval的最后一项也被选中的话,此时经过Replace后,只会剩下一个分隔符                    {                        selectedValue += splitStr;        //添加一个分隔符                    }                }            }            selectedValue = selectedValue.Substring(1, selectedValue.Length - 2);        //除去前后加的分割符号

2009-10-30 0comments 98hotness 0likes mikebai Read all
DotNET

客户端动态注册 JavaScript

在 ASP.NET2.0 中有一个专门用来管理客户端 JavaScript 脚本的类 ClientScriptManager这样我们可以根据程序需要动态的注册所需的 JavaScript 脚本程序它具有四种方式I   RegisterClientScriptBlock    将 JavaScript 区块添加到页面头部 [Head]。    可 以字符创形式创建这些代码,然后将它传递给添加网页的方法。可以使用这种方式将任何 JavaScript 插入网页。    对应的检测注册方法    Page.ClientScript.IsClientScriptBlockRegistered()       Sample:   protected void Page_Load(Object sender, EventArgs e){    //动态建立 JavaScript    string info = "";    info += "function showName(username)";    info += "{alert('您的名字是' + username);}";    //判断 myName 是否已被注册    if(!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "myName"))    {        //动态注册 JavaScript        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myName", info, true);    }} II  RegisterClientScriptInclude    这种方法类似上一种方法,但是会添加引用外部 .js 文件的 JavaScript 区块。    在以动态方式添加任何其他 JavaScript 之前就会添加这个包含文件。因此您可能无法引用网页上的某些项目。    对应的检测注册方法    Page.ClientScript.IsClientScriptIncludeReg

2009-10-27 0comments 94hotness 0likes mikebai Read all
DotNET

Silverlight cross domain policy file helpers

If you are starting to get into integrating web services with Silverlight, you'll notice that you have to have a cross domain policy file in place on the target server, that is to say, the server hosting the service you want to implement.  There are some public web services (Flickr, YouTube, Digg, etc.) that already have these files in place for Flash, but implement in a slightly different way. When calling a cross-domain service, Silverlight will check for the existence of clientaccesspolicy.xml first.  This is the format defined by Silverlight and provides a pretty flexible way to define who can access what services.  If not found, it will then default to look for crossdomain.xml, which is the file format implemented for Adobe Flash.  It is important to note that this file will also still work for most public web services. But now perhaps you are the author of the service that your application is going to consume and/or the public will consume.  There are a few things you want to consider.  First, it would be a best practice to put your service layer on a separate domain other than your site (i.e., api.mysite.com).  In fact, this is how most are doing it these days.  These helps separate more distinctly the services from the web site and also separates the cross-domain security concerns away from the content site versus API access.  Once you have done that you'll want to implement your specific clientaccesspolicy.xml file. When Silverlight 2 was released to beta, I created some quick helper files to assist me with…

2009-10-23 0comments 114hotness 0likes mikebai Read all
DotNET

MSDN的关于跨域访问

http://msdn.microsoft.com/en-us/library/cc645032(VS.95,printer).aspx  

2009-10-23 0comments 100hotness 0likes mikebai Read all
DotNET

SilverLight跨域访问及其常用的几种解决方法

今天在做silverlight访问JSon数据的时候老是出现错误,才发现是跨域的问题,因此将这方面的内容整理一些,列了出来 SilverLight 出于对安全性的考虑默认情况下对URL的访问进行了严格的限制,只允许访问同一子域下的URL资源。下表列出了Silverlight 2.0 中 URL 访问规则:   WebClient对象 Media、images、ASX XAML 文件、Font 文件 流媒体 允许的协议 HTTP, HTTPS HTTP, HTTPS, FILE HTTP, HTTPS, FILE HTTP 跨协议访问 不允许 不允许 不允许 不允许来自HTTPS的访问 跨Web域访问 不允许 如果不是来自HTTPS则允许 不允许 允许 跨安全区域访问(Windows) 不允许 不允许 不允许 不允许 跨安全区域访问(Macintosh) 不允许 允许 不允许 允许 允许重定向 同域允许 允许 同域允许 不允许 如果WCF与SilverLight Web不是在同一站点,那么我们就要在被访问端的根域放上两个XML文件clientaccesspolicy.xml,crossdomain.xml如果要通过WebClinet访问另一站点的资源,那么需要在被访问站点放上域访问策略xml文件,不然在Complete事件里面的事件参数报告空对象引用。 clientaccesspolicy.xml文件格式如何,切忌最好要将编码设置为utf-8,否则极易出错 <?xml version="1.0" encoding="utf-8"?><access-policy>    <cross-domain-access>        <policy>            <allow-from>                <domain uri="*"/>            </allow-from>            <grant-to>                <resource path="/" include-subpaths="true"/>            </grant-to>        </policy>    </cross-domain-access></access-policy> crossdomain.xml文件格式 crossdomain.xml的格式非常简单,其根节点为<cross-domain-policy> ,其下包含一个或多个<allow-access-from>节点,<allow-access-from>有一个属性domain,其值为允许访问的域,可以是确切的 IP 地址、一个确切的域或一个通配符域(任何域)。下边是两个例子: 程序代码<?xml version="1.0"?><cross-domain-policy>  <allow-access-from domain="http://www.lishewen.com.cn/" />  <allow-access-from domain="*.lishewen.com.cn" />  <allow-access-from domain="222.217.221.16" /></cross-domain-policy> 程序代码<?xml version="1.0"?><cross-domain-policy>  <allow-access-from domain="*" /></cross-domain-policy> 第二个例子允许任何域的访问。对于crossdomain.xml文件存放位置,建议将其存放于站点根目录中! 如:http://bbs.lishewen.com.cn/crossdomain.xml 在这我也弄了个Silverlight的例子来测试 http://silverlight.lishewen.net.cn/SyndicationFeedReader/ 关于clientaccesspolicy.xml,crossdomain.xml的具体说明,请大家参看MSDN  http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx 文章整理资料来源于:http://www.cnblogs.com/format/articles/1282203.html                http://blog.lishewen.com.cn/post/2008/06/e4bdbfe794a8crossdomainxmle8aea9Silv

2009-10-23 0comments 102hotness 0likes mikebai Read all
DotNET

Silverlight 跨域的策略文件 clientaccesspolicy.xml

Silverlight 跨域的策略文件 clientaccesspolicy.xml  <?xml version="1.0" encoding="utf-8"?><access-policy>    <cross-domain-access>        <policy>            <allow-from>                <domain uri="*"/>            </allow-from>            <grant-to>                <resource path="/" include-subpaths="true"/>            </grant-to>        </policy>    </cross-domain-access></access-policy>   文件编码一定要改成 utf-8  不改的话跨域失败   文件一定要放在网站根目录下 ??????? ???? Love ????? http://www.seewind.cn

2009-10-23 0comments 113hotness 0likes mikebai Read all
DotNET

Silverlight反编译

反编译.NET应用程序已经成为一种很常见的工作方法,而类似Reflector这样的工具使得这项工作更容易了。反编译一个应用程序的原因通常包括了学习编译器是如何转换代码,避开程序库的限制,或直接窃取他人的成果。在浏览器世界里,普遍认为 "查看源文件"是学习如何编码的一个主要手段。 撇开法律上的影响,反编译Silverlight 2应用程序是一件很容易的事情。Silverlight应用程序的所有文件都存储在一个扩展名为XAP的zip压缩文件里。它包含了应用程序所需的所有 XAML、DLL和config文件。一旦解压缩,DLL文件就可以用ILDASM或者你喜欢的反编译器打开。  

2009-10-23 0comments 101hotness 0likes mikebai Read all
DotNET

ASP.NET Web 应用程序与ASP.NET网站比较

  网站编译速度快,使用了增量编译模式,仅仅只有文件被修改后,这部分才会被增量编译进去。   生成的程序集 WebSite:生成随机的程序集名,需要通过插件WebDeployment才可以生成单一程序集 WebApplication:可以指定网站项目生成单一程序集,因为是独立的程序集,所以和其他项目一样可以指定应用程序集的名字、版本、输出位置等信息   可以将网站拆分成多个项目以方便管理   可以从项目中和源代码管理中排除一个文件   支持VSTS的Team Build方便每日构建   更强大的代码检查功能,并且检查策略受源代码控制   可以对编译前后进行自己规定的处理   对App_GlobalResources 的Resource强类支持(网上说的,还没有了解过)   直接升级使用VS2003构建的大型系统   WebSite编程模型的优点:   动态编译该页面,马上可以看到效果,不用编译整个站点(主要优势)   同上,可以使错误的部分和使用的部分不相干扰(可以要求只有编译通过才能签入)   可以每个页面生成一个程序集(不会采用这种方式)   可以把一个目录当做一个Web应用来处理,直接复制文件就可以发布,不需要项目文件(无所谓,只适合小站点)   可以把页面也编译到程序集中(应该用不到,而且WebApplication也可以通过WebDeployment插件来实现)   两种编程模型的互相转换:   VS2005 SP1内置了转换程序,可以非常方便的从WebSite转换到WebApplication 只需要复制文件,右键执行“转换为Web应用程序”即可。未查到有专门的反向转换工具,但比较后发现如果转换也非常简单。   删除所有*.designer.cs 将*.aspx、*.ascx、*.master页面文件中的 Codebehind="FileList.aspx.cs" 批量替换成 CodeFile="FileList.aspx.cs"

2009-10-15 0comments 100hotness 0likes mikebai Read all
DotNET

CodeFile、Src、Codebehind

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="_Default" %> <%@ Page Language="C#" AutoEventWireup="true" Src="default.aspx.cs" Inherits="_Default" %> <%@ Page Language="C#" AutoEventWireup="true" Codebehind="default.aspx.cs" Inherits="_Default" %> 以上三句,具体差别在哪? --------------------------------------------------------------- src表示该aspx的源文件 codefile表示将运行时编译,比如VS2005中新建一个网站你会发现编译比WEB应用程序慢很多,但是可以修改代码后不用整体编译刷新页面就可以看到效果 codebehind就象.netfw1.1一样编译完后所有cs中的代码打包进dll --------------------------------------------------------------- CodeBehind: 指定包含与页关联的类的已编译文件的名称。该属性不能在运行时使用。 提供此属性是为了与以前版本的 ASP.NET 的兼容,以实现代码隐藏功能。在 ASP.NET 2.0 版中,应改用 CodeFile 属性指定该源文件的名称,同时使用 Inherits 属性指定该类的完全限定名称。   CodeFile   指定指向页引用的代码隐藏文件的路径。此属性与 Inherits 属性一起使用可以将代码隐藏源文件与网页相关联。此属性仅对编译的页有效。 --------------------------------------------------------------- src 好象是 ASP.NET 1.x 才会有,2.0 的 code-behind 变成 CodeFile 了 . Code-Behind 的好处就是它可以被编译,会比直接写在网页上的直译程序快,而且可以防止程序代码外泄的问题     移动项目开发笔记(用户控件引起对asp.net 2.0编译的思考) 来源:http://www.ittang.com/2008/0627/7216.html   一、起因:          开发团队的一名开发人员突然离职,他把他负责的模块任务交给了我。其中一个模块是他写了一个用户控件,我在我的页面尚始终都用不起,运行时发生错误,错误消息是:The base class includes the field *****, but its type (****) is not compatible with the type of control (ASP.webusercontrol_ascx). 二、经过:    遇到这个问题后个人感觉那个用户控件在页面上注册没有成功。查找了页面注册代码: <%@ Register Src="ProjectInfo.ascx" TagName="ProjectInfo" TagPrefix="uc3" %><uc3:ProjectInfo ID="ProjectInfo1" runat="server"&n

2009-10-15 0comments 105hotness 0likes mikebai Read all
DotNET

通过win32api让c#控制Windows任务栏

如果你要在你的C#程序中控制Windows的任务栏,有两个Windows api 可以帮到你!他们就是  FindWindowA 和 ShowWindowC#中声明如下:using System.Runtime.InteropServices;[DllImport("user32.dll", EntryPoint = "FindWindowA")]public static extern IntPtr FindWindowA(string lp1, string lp2);[DllImport("user32.dll", EntryPoint = "ShowWindow")]public static extern IntPtr ShowWindow(IntPtr hWnd, int _value);其实Windows的任务栏就是一个特殊的窗口,所以操作窗口的方法,对任务栏一样适合!控制代码如下://获取任务栏IntPtr hTray = Form1.FindWindowA("Shell_TrayWnd", String.Empty);//显示任务栏Form1.ShowWindow(hTray, 5);//隐藏任务栏Form1.ShowWindow(hTray, 0);     原文:http://www.pinvoke.net/default.aspx/user32/DrawAnimatedRects.html  C# Signature: [DllImport("user32.dll")]static extern bool DrawAnimatedRects(IntPtr hwnd, int idAni,   [In] ref RECT lprcFrom, [In] ref RECT lprcTo);  User-Defined Types: IDANI_ Notes: Only the IDANI_CAPTION constant will result in any animation. Any other constants have not been implemented on any Windows platform! Tips & Tricks: Since only IDANI_CAPTION is implemented, to get the effect of IDANI_OPEN, simply swap the lprcFrom and lprcTo rectangles, but still specify the IDANI_CAPTION constant. Sample Code:     /// <summary>    /// This constant is not implemented on any Windows platform!    /// </summary>    public const System.Int32 IDANI_OPEN = 1;    /// <summary>    /// The window caption will animate from lprcFrom to lprcTo.    /// </summary>    public const System.Int32 IDANI_CAPTION = 3;    [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]    struct RECT     {      public RECT(System.Drawing.Rectangle rectangle)       {        Left = rectangle.Left;        Top = rectangle.Top;        Right = rectangle.Right;        Bottom = rectangle.Bottom;      }      public RECT(System.Drawing.Point location, System.Drawing.Size size)       {        Left = location.X;        Top = location.Y;        Right = location.X + size.Width;        Bottom = location.Y + size.Height;      }      public System.Int32 Left;      public System.Int32 Top;      public System.Int32 Right;      public System.Int32 Bottom;    }    [System.Runtime.InteropServices.DllImport("user32.dll")]    static extern bool DrawAnimatedRects(System.IntPtr hwnd, int idAni,      [System.Runtime.InteropServices.In] ref RECT lprcFrom,       [Sy

2009-10-12 0comments 108hotness 0likes mikebai Read all
1…1213141516

Recent Posts

  • c# winform适配高dpi
  • com.microsoft.sqlserver.jdbc.SQLServerException “trustServerCertificate”属性设置为“false”,但驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server建立安全连接
  • java -cp 用法介绍
  • HTML 容器元素
  • MVC的cshtml的介绍

Recent Comments

No comments to show.

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang