您的位置:首页 > 编程语言 > ASP

Asp.Net初学小结 判断数组中是否有重复的数据

2018-03-22 14:21 651 查看

Asp.Net初学小结

  第一章   1.搭建Asp.net开发环境   1).net FrameWork(VS) 2)IIS(xp:5.1,2003:6.0,vista:70,win7:7.5) C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -i [重新注册]   2.Asp.net的优势   1)丰富的控件库 2)代码后置 3)方便调试 4)编译后执行 5)与浏览器无关   第二章   1.Asp.net运行机制   Asp.net引擎(Aspnet_isapi.dll:管道模型) 一.处理请求:httpModule(过滤请求)→httpHandle(处理请求) 二:设置httpHandlers Public bool IsReusable{get{return ture;}}(设置httpHandlers)   三.在Web.config中添加httpHandlers <httpHandlers><add path="" type="" verb=""><httpHandlers/>   2.Asp.net系统对象   1)Page   2)Request[接受请求中的数据] 接受表单数据:Request.From[""] 接受问号传值:Request.QueryString[""] 3)Response[输出] 一:跳转 Response.Rediect("") 二:输出:Response.Write("") 三:提示:Alert("") 四:确认:return confirm("")   4)Server[封装服务器常用方法属性] 一:Server.MapPath("") 二:Server.HtmlEncode("")编码   3.数据传递   1)页内传递 一.用This.获取控件得到属性值 二.隐藏控件   2)页面传递 一.问号传值(get传值,Request.QueryString[""],大小限制255字节)   二.表单传值(Post传值,Request.From[""]) 跨页提交(PostBackUrl="",PreviousPage.FindControl("控件类型") as 控件类型)   三.状态保持方式:Session,Cookie等等   4.状态保持方式   1)Session(保存在服务端,操作方便,容易丢失) 一:保存Session:Session[""] = 对象或者字段 二:获取Session:对象(字段)= Session[""] as 对象类型   2)Cookie(保存在客服端,只能存文本,自定义有效期,不安全) 一:创建Cookie:HttpCookie httpCookie = new HttpCookie() httpCookie.Values["名称"] = ""; 二:设置有效期:httpCookie.Expires = DateTime.Now.Add(); 三:添加Cookie:Response.Cookies.Add(httpCookie) 四:获取Cookie:Response.Cookie[""].Values["名称"] = 字段;   3)Application(保存在服务端,全局共享,保存网站配置数据) 锁定Application防止死锁 一:创建Global.asax 二:锁定Application:Application.Lock() 三:创建Application:Application["名称"] = "" 四:解锁Application:Application.Unlock()   4)ViewState(保存在服务端,页面内有效)   第三章(Asp.net控件)   母版页(统一布局) 一:创建母版页:MasterPage.master 二:公共内容控制:ContentPlaceHolder 三:添加子夜:创建页面时选择母版页   1.导航控件   1)SiteMapPath(层次导航) 创建SiteMap,控件自动获取SiteMapPath的数据 <siteMapNode url="" title="" description="" > <siteMapNode url="" title="" description="" /> <siteMapNode/>   2)Menu(菜单) 一:用SiteMapPath或者XML绑定数据源 二:设置静态、动态的显示级数,和水平显示 3)TreeView(树形导航) 创建TreeView,用SiteMapPath或者XML绑定数据源,用XML需要指定绑定的值   2.数据绑定控件   1)DropDownList(下拉刘表) 一:数据源绑定,创建DropDownList,指定ID和Value   二:手动绑定 this.DropDownList.DataSource() this.DropDownList.DataTextFiled = "" this.DropDownList.DataValueFiles = "" this.DropDownList.Bind()   三:给DropDownList添加一项 数据绑定 添加DataBound事件:this.DropDownList.Items.Insert(0,new ListItem("---请选择---","") 手动绑定 this.DropDownList.Items.Insert(0,new ListItem("---请选择---","")   四:级联 数据绑定时 给子DropDownList设置数据源,指定获取值的控件,并给默认值,在父控件里设置AuotPostBack 手动绑定,添加SelectIndexChanged       2)GridView(展示表数据) 一:数据绑定 SqlDataSource绑定,创建GridView,做编辑、删除需要在高级选项里打勾 对象绑定,创建GridView,编辑、删除需要自己添加自定义项 手动绑定:this.GridView.DateSource = 方法 数据源绑定:this.GridView.DateSourceID = this.数据源.ID   二:页面绑定数据,并格式化,添加方法,如果绑定前后有字符,需要{0}作为参数 <%#方法(Eval("对象.属性","{0:}")).ToString(),参数)%>   三:光棒效果 添加RowDataBound事件 e.Row.Attributes.Add("onmouseover","oldColor=this.style.backgroundColor;this.style.backgroundColor = '颜色'") e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=oldColor")   四:数据源绑定不能自动绑定外键,需要手动绑定[获取当前下拉框Row的值] 在页面中添加SelectValue = '<%#Eval("对象.属性") %>' 更新时,添加RowUpdating事件 This.数据源.UpdateParameters["字段"].DefautValue = (this.GridView.Rows[e.RowIndex].FindControl("控件") as 控件类型).SelectValue   五:设置GridView主键(DateKeyName = "主键值")   六:在GridView做命令提交时,需要在RowCommand事件中写代码 e.CommandName(""),需要在控件里设置CommandName = "" e.CommandArgument = <%#Eval("对象.属性") %>  3)DetailView(展示详细信息)   4)DataList(可自定义模版) 一:数据绑定 手动绑定:this.DataList.DateSource = 方法 数据源绑定:this.DataList.DateSourceID = this.数据源.ID   二:模版 头模版、Item模版、脚模版、交替项模版、分隔符模版、选择模版、编辑模版   三:分页 PagedDataSource分页 1创建PagedDataSource对象 PagedDataSource pds = new PagedDataSource(); 2打开分页开关 pds.AllowPaging = true; 3,设置页大小 pds.PageSize = 大小; 4设置当前页,注意CurrentPageIndex是索引,第一页为0 pds.CurrentPageIndex = pageIndex-1; 5设置数据源 pds.DataSource = 数据源   绑定分页控件 this.UcfarPager1.PageStyle = UcfarPagerControls.PagerStyle.前后缩略; this.UcfarPager1.PagePara = "p"; this.UcfarPager1.PageSize = pds.PageSize; this.UcfarPager1.RecordCount = pds.DataSourceCount;   存储过程分页 create proc Pager @tableName varchar(20), @orderBy varchar(20) ='id', @whereStr varchar(100)='', @pageIndex int=1, @pageSize int=10 as declare @sqlStr varchar(200) declare @startRowIndex int , @endRowIndex int set @startRowIndex = (@pageIndex-1)*@pageSize+1 set @endRowIndex = @pageIndex*@pageSize   if(@whereStr!='')     set @whereStr = ' where ' + @whereStr set @sqlStr='select * from (select row_number() over(order by '  + @orderBy  + ') as rowindex, * from ' + @tableName+ @whereStr  + ') as newTab where rowIndex between '  + convert(varchar(4),@startRowIndex) + ' and '  + convert(varchar(4),@endRowIndex) print @sqlStr exec(@sqlStr) 5)Repeater(精确布局) 一:数据绑定 手动绑定:this.Repeater.DateSource = 方法 数据源绑定:this.Repeater.DateSourceID = this.数据源.ID   二:模版 头模版、Item模版、脚模版、交替项模版、分隔符模版     3.验证控件[选择控制的控件] 验证中有两个提交控件时,需要给控件分组   1)非空验证 RequiredFieldValidator 填写错误信息   2)范围验证 RangeValidator 需要设置ControlToCompare[比较的控件] ValueToCompare [比较的值]   3)自定义验证 CustomValidator  后台验证事件 ServerValidate args.Value [验证的值] args.IsValid [验证结果] 前台验证 注册ClientValidtionFunction事件 Fun中需要两个参数(obj,e)   4)正则表达式验证 RegularExpressionValidator 填写错误信息和ValidatorExpression   5)错误信息汇总控件 ValidationSummary 有MessageBox和Summary两种显示模式            
public bool IsRepeat(string[] yourValue)
{
Hashtable ht = new Hashtable();
for (int i = 0; i < yourValue.Length - 1; i++)
{
if(ht.Contains(yourValue[i]))
{
return true;
}
else
{
ht.Add(yourValue[i], yourValue[i]);
}
}
return false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: