【asp.net中控制反转的理解(文字+代码)】教程文章相关的互联网学习教程文章

Asp.Net 动态页面转静态页面主要代码

一个是一个页面转换的类,该类通过静态函数Changfile()来实现,动态页面到静态页面的转换。   代码如下:using System;   using System.Data;   using System.Configuration;   using System.Web;   using System.Web.Security;   using System.Web.UI;   using System.Web.UI.WebControls;   using System.Web.UI.WebControls.WebParts;   using System.Web.UI.HtmlControls;   using System.Text;   using...

asp.net DropDownList 三级联动下拉菜单实现代码

代码如下:if (!IsPostBack) { //一级分类列表 this.DropDownList1.DataSource = dsbb.SelectSubjct1(); this.DropDownList1.DataTextField = "cName"; this.DropDownList1.DataValueField = "Ccode"; this.DropDownList1.DataBind(); this.DropDownList1.Items.Insert(0,new ListItem("请选择一级分类","0")); this.DropDownList8.Items.Insert(0, new ListItem("请选择二级分类", "0")); this.DropDownList9.Items.Insert(0,new L...

asp.net 读取并修改config文件实现代码

1. 向项目添加app.config文件: 右击项目名称,选择“添加”→“添加新建项”,在出现的“添加新项”对话框中,选择“添加应用程序配置文件”;如果项目以前没有配置文件,则默认的文件名称为“app.config”,单击“确定”。出现在设计器视图中的app.config文件为: <?xmlversion="1.0"encoding="utf-8" ?> <configuration> </configuration> 在项目进行编译后,在bin\Debuge文件下,将出现两个配置文件(以本项目为例),一个名为“...

asp.net 代码隐藏的编码模型【图】

一.内联代码与代码隐藏 代码隐藏模型相对内联代码的优势: 1.逻辑代码和html的分离,使得我们可以更专注于业务逻辑的处理。 2.使业务逻辑更加清晰。 3.可以将后置代码编译成dll,使得程序更加安全。 二.后置代码与页面的关系和机制 与代码后置模型相关的三个类。 1.基页面类 page类 .net类库中的page类,page类定义了页面的基本功能。例如:允许存放其他控件、呈现html、提供对asp.net对象的访问(如request、response、session等)...

.NET 中英文混合验证码实现代码【图】

最终效果如图: CheckCode.aspx.cs代码如下 代码如下:protected void Page_Load(object sender, EventArgs e) { //获取GB2312编码页(表) /**//** * 生成中文验证验码所要使用的方法 * 注,生成中文验证码时要改变一下生成验证码图片的宽度 * var imageCode = new System.Drawing.Bitmap((int)Math.Ceiling((code.Length * 22.5)), 23); //定义图片的宽度和高度 **/ //var gb = Encoding.GetEncoding("gb2312"); /**/////调用函数...

asp.net 产生随机颜色实现代码

代码如下:public string GetRandomColor() { Random RandomNum_First = new Random((int)DateTime.Now.Ticks); // 对于C#的随机数,没什么好说的 System.Threading.Thread.Sleep(RandomNum_First.Next(50)); Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks); // 为了在白色背景上显示,尽量生成深色 int int_Red = RandomNum_First.Next(256); int int_Green = RandomNum_Sencond.Next(256); int int_Blue = (int...

asp.net 动态引用样式表代码

1. 添加CSS样式: Style style = new Style(); style.ForeColor = System.Drawing.Color.Navy; style.BackColor = System.Drawing.Color.LightGray; this.Header.StyleSheet.CreateStyleRule(style, null, "body"); 2. 链接外部的CSS样式表: HtmlLink link = new HtmlLink(); link.Attributes.Add("type", "text/css"); link.Attributes.Add("rel", "stylesheet"); link.Attributes.Add("href", "~/newstyle.css"); this.Header.Con...

asp.net关于onpropertychange和oninput事件实现代码

整体思路是这样,当文本框的值改变时触发事件,对列表中原有的值进行过滤。 根据这个思路,首先需要解决的无非是确定文本框的什么事件可以满足要求,当时第一个想到的是onkeydown或者onkeypress,在试的过程中发现再输入中文时,无法响应,因为输入方会将焦点给屏蔽了。在网上寻觅了一会发现onpropertychange事件为改变文本属性时就会出发,所以当文本框输入数据的时候其实是在改变文本框的value属性。而且中文也可以满足,本以为大...

ASP.NET(C#) 定时执行一段代码

Global.asax C# code 代码如下:<%@ Application Language="C#" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Threading" %> <script runat="server"> string LogPath; Thread thread; void WriteLog() { while (true) { StreamWriter sw = new StreamWriter(LogPath, true, Encoding.UTF8); sw.WriteLine(thread.Name + ":" + DateTime.Now.ToString()); sw.Close(); Thread.CurrentThread.Join(1000 * ...

asp.net下将Excel转成XML档的实现代码

代码如下:if (this.FileUpload1.PostedFile != null) { string filename = this.FileUpload1.FileName.ToString(); string path = @Server.MapPath("../File/") + filename; this.FileUpload1.PostedFile.SaveAs(path); //读取用户上传的Excle文件 string conn="Provider = Microsoft.Jet.OLEDB.4.0 ;Data Source ='"+path+"';Extended Properties=Excel 8.0"; OleDbConnection olecon = new OleDbConnection(conn); olecon.Open()...

asp.net url分页类代码

代码如下:using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Text; /// <summary> ///CutPage 的摘要说明 /// </summary> public class CutPage { public CutPage() { // //TODO: 在此处添加构造函数逻辑 // } #reg...

C# 数组查找与排序实现代码

1. 查找对象 代码如下:Person p1 = new Person( " http://www.my400800.cn " , 18 ); Person p2 = new Person( " http://www.my400800.cn " , 19 ); Person p3 = new Person( " http://www.my400800.cn " , 20 ); Person[] persons = ... { p1, p2, p3 } ; // 查找p2所在数组中的位置 Array.IndexOf < Person > (persons, p2); 2. 查找值 代码如下:Person p1 = new Person( " http://www.my400800.cn " , 18 ); Person p2 = new...

asp.net 图片的读写入库实现代码

写图片c:\1.jpg到表cinfo中 代码如下:private static void AddCinfo() { string strSql = "insert into cinfo (srvtitle,csttitle,introduction,logo) values (@srvtitle,@csttitle,@introduction,@logo)"; SqlParameter[] parms = { new SqlParameter("@srvtitle",SqlDbType.VarChar,30), new SqlParameter("@csttitle",SqlDbType.VarChar,30), new SqlParameter("@introduction",SqlDbType.NVarChar,500), new SqlParameter("@l...

ASP.NET 调用百度搜索引擎的代码

百度搜索引擎提供了一段嵌入到页面中的代码 <form action="http://www.baidu.com/baidu" target="_blank"> <table><tr><td> <input name=tn type=hidden value=baidu> <input type=text name=word size=80> <input type=hidden name=ie value="UTF-8"> <input type="submit" style="background:url(images/searchicon.gif) no-repeat; border:0; width:76px; height:26px; cursor:pointer" value="搜索"> </td></tr></table> </for...

.NET 常用功能和代码小结

1. 打开新的窗口并传送参数: 传送参数: response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>") 接收参数: string a = Request.QueryString("id"); string b = Request.QueryString("id1"); 2.为按钮添加对话框 传送参数: response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>") 接收参数: string a = Request...