用aspx写的餐饮网站总结

餐饮网站开发主要技术总结 局部刷新 Users.aspx和home.aspx用到了ajax的局部刷新技术,其格式如下 Aspx页面(主要起作用的是ScriptManager 和 UpdatePanel)
您現在的位置是:首頁 > 关于我们
<%-----------------第二层开始(公司介绍)-----------------------%>
您現在的位置是:首頁 > 关于我们 > 公司介绍
而当要在具备局部刷新页面中弹出消息框的时候,必须要用到ScriptManager.RegisterStartupScript Cs代码片段如下 ScriptManager.RegisterStartupScript (this.UpdatePanel3, this.GetType(), "msg3", "alert('留言成功,等待审核后可见!');", true); 页面权限: 页面验证没用到session,而是建一个用户类来存储用户信息 namespace eatModels { public class UserHelper { public static string userid; public static string userpwd; public static string username; public static string sendad; public static string sex; public static int sendphone; public static int userpoint; public static int adshowType; } } 当用户输入用户名和密码得到数据库验证成功后,将用户信息保存在UserHelper类里面,然后当某些页面需要用户验证的时候,调用UserHelper中的静态变量 Users.cs用户验证代码片段 //登陆判断 if (UserHelper.username == null && UserHelper.sendphone == 0) { Response.Write("<script>alert('请先登录!');window.opener=null;window.close();window.open('Home.aspx');</script>"); } Repeater控件+翻页显示 Aspx代码片段
用户名: <%# DataBinder.Eval(Container.DataItem, "messagesid") %>          留言时间: <%# DataBinder.Eval(Container.DataItem, "messagetime") %>
留言: <%# DataBinder.Eval(Container.DataItem, "Messagebody", "{0:N2}") %>

管理员回复: <%# DataBinder.Eval(Container.DataItem, "reply", "{0:N2}") %>
上页 下页 第 页 共 页 Cs代码片段 //分页绑定 private void myBind() { // 数据源 PagedDataSource Pgds = new PagedDataSource(); // Pgds.DataSource=CreateDataSource().DefaultView; Pgds.DataSource = CreateDataSource().DefaultView; // 设置允许分页 Pgds.AllowPaging = true; // 每页显示为6行 Pgds.PageSize = 4; // 显示总共页数 // lblTotalPage.Text = Pgds.PageCount.ToString(); // 当前页 int CurrentPage; // 请求页码为不为null设置当前页,否则为第一页 if (Request.QueryString["Page"] != null) { CurrentPage = Convert.ToInt32(Request.QueryString["Page"]); } else { CurrentPage = 1; } // 当前页所引为页码-1 Pgds.CurrentPageIndex = CurrentPage - 1; // 显示当前页码 lblCurrentPage.Text = CurrentPage.ToString(); // 如果不是第一页,通过参数Page设置上一页为当前页-1,否则不显示连接 if (!Pgds.IsFirstPage) { // Request.CurrentExecutionFilePath为当前请求虚拟路径 lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1); } // End If // 如果不是最后一页,通过参数Page设置下一页为当前页+1,否则不显示连接 if (!Pgds.IsLastPage) { // Request.CurrentExecutionFilePath为当前请求虚拟路径 lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1); } // 模板绑定数据源 Repeater1.DataSource = Pgds; Repeater1.DataBind(); } public DataTable CreateDataSource() { DataTable dt = um.GetMessage().Table; return dt; } GridView中的翻页功能(AllowPaging="True"和onpageindexchanging="gvSelectAll_PageIndexChanging") Aspx代码片段 Cs代码片段 //gvSelectAll翻页事件 protected void gvSelectAll_PageIndexChanging(object sender, GridViewPageEventArgs e) { if (gvSelectAll.EditIndex != -1) { e.Cancel = true; int newPageNumber = e.NewPageIndex + 1; } else { gvSelectAll.PageIndex = e.NewPageIndex; this.gvSelectAll.DataSource = um.selectAllOrder().Table; gvSelectAll.DataBind(); } } 图片上传 Aspx代码片段 Cs代码片段 protected void btnUpdateImgs_Click(object sender, EventArgs e) { string root = Server.MapPath("~/"); string path = "/addAll/imgList/"; string mpath = path + FileUpload1.FileName; bool fileOK = false; if (FileUpload1.HasFile) { //返回文件的扩展名 String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); //设置限制的文件类型 String[] allowExtension = { ".jpg", ".gif", ".bmp" }; //判断用户选择的文件类型是否受限制 for (int i = 0; i < allowExtension.Length; i++) { if (fileExtension == allowExtension[i]) { fileOK = true; } } } if (mmm.Confirms(mpath))//调用mmm.Confirms()验证图片是否已经存在 { Response.Write("<script language=javascript>alert('该图片已存在!');</script>"); } if (!fileOK) { Response.Write("<script>alert('图片格式不正确!');</script>"); } if (txtID.Text=="") { Response.Write("<script>alert('图片标题不能为空!');</script>"); } if (mmm.Confirms(mpath) == false && fileOK &&txtID.Text.Trim()!="") { FileUpload1.PostedFile.SaveAs(root + path + FileUpload1.FileName); addImg img = new addImg(); img.ImgName = txtID.Text.Trim(); img.ImgAddress = path + FileUpload1.FileName; if (mmm.insertImgs(img)!=0) { Response.Write("<script>alert('上传成功!');</script>"); } } } 图片展示+翻页 Aspx代码片段
Cs代码片段 protected void BindToGridView() { //获取文件名称 //string[] files = Directory.GetFiles(Server.MapPath(imagepath)); string[] files = Directory.GetFiles(Server.MapPath("/addAll/imgList/")); //建立数据表 DataTable dt = new DataTable(); //dt.Columns.Add("filename"); //dt.Columns.Add("size"); dt.Columns.Add("filePath"); foreach (string s in files) { DataRow dr = dt.NewRow(); FileInfo f = new FileInfo(s); dr["filePath"] = "/addAll/imgList/" + f.Name; dt.Rows.Add(dr); } //绑定显示 this.GridView1.DataSource = dt; this.GridView1.DataBind(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { this.GridView1.PageIndex = e.NewPageIndex; this.BindToGridView(); //调用上面的BindToGridView()绑定 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值