网站开发常用功能

一、点击删除时跳出一个提示是否确定删除

<a style="float:right;" οnclick="if(confirm('确认删除吗?')==false)return false;" href="lookdv.aspx?id=<%=li.Id %>">删除视频</a>

二、ASP循环遍历展示数据

1. 首先拿到数据源

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="lookdv.aspx.cs" Inherits="ShortArticle.lookdv" %>
<%
    ShortArticle.DAL.ShortArticleService service = new ShortArticle.DAL.ShortArticleService();
    List<ShortArticle.Model.ShortArticleModel> list = service.GetShortArticle(20);
    ShortArticle.Model.CustomerModel customer = new ShortArticle.Model.CustomerModel();
    if (Session["UserInfo"] != null)
    {
        customer = Session["UserInfo"] as ShortArticle.Model.CustomerModel;
    }
%>
<%@ Import Namespace="ShortArticle.Model" %>

2. foreach遍历循环输出

   <%foreach (LookdvModel li in list)
                            { %>
                        <div class="bubble-list mar16-t" id="bubbleListHome">
                        <div class="bubble-list-item box mar16-b " id="bubbleList22116">
                            <div class="pd10 bubble-list-item-h fs12 gray clearfix">
                                <a id="user-71" class="users" href="#"><%=li.CustomerName %></a>        <span class="dot"></span>        
                                <time class="timeago" datetime="2019-09-14T22:38:39+00:00" data-timeago="2019-9-14 22:38:39" ref="timeAgo" data-tid="48"></time>
                                <a style="float:right;" οnclick="if(confirm('确认删除吗?')==false)return false;" href="lookdv.aspx?id=<%=li.Id %>">删除视频</a>
                            </div>
                            <div class="pd10 b-t entry-content pos-r">
                                <div class="entry-content-in">
                                    <p><%=li.text %></p>
                                   <video width="320" height="240" controls>
                                    <source src="<%=li.url%>" type="video/ogg">
                                    <embed width="320" height="240" src="movie.swf">
                                       </object>
                                     </video>
                                </div>
                            </div>
                        </div>

                        <%} %>

三、if语句的使用,就是指当前标签在成立的情况下才会显示出来。下方实现的是当session的值等于null的时候显示提示登陆,else显示登陆信息。

                  <%if (Session["UserInfo"] == null)
                      {
                  %>
                    <button type="button" class="navbar-right btn btn-default navbar-btn" οnclick="window.location='Register.aspx'">注册</button>
                    <button type="button" class="navbar-right btn btn-success navbar-btn u-mr--10" οnclick="window.location='Login.aspx'">登录</button>
                  <%}%>
                <%
                    else
                    {%>
                <div  style="font-size:16px; float:right; margin-right:20px; margin-top:10px;">
                     欢迎回来~<span style="color:blue; font-size:18px;"><a><%=customer.CustomerName%></a></span>
                     <a style="background-color:#f2f2f2; color:red; margin-left:10px; padding:6px 10px 6px 10px;" href="javascript:Exit()">退出</a>
                </div>
               
                    <%}
                  %>

四、aspx,上传文件的后台代码

  if (FileUpload1.HasFile)
            {
                
                string fileName = "." + FileUpload1.FileName.Split('.')[1];
                if (fileName == ".mp4" || fileName == ".ogg" || fileName == ".webm")
                {
                    //1.对上传文件进行重命名?
                    string newfileName = Guid.NewGuid().ToString();  //生成一个唯一码
                                                                     //2:将上传的文件放在不同的目录下面,获取当前日期的年月日
                    string dir = "/file/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/";
                    /// 创建文件夹
                    if (!Directory.Exists(Context.Request.MapPath(dir)))
                    {
                        Directory.CreateDirectory(Context.Request.MapPath(dir));
                    }
                    string fullDir = dir + newfileName + fileName;
                    FileUpload1.SaveAs(Context.Request.MapPath(fullDir));
                    l.url = fullDir;
                    bool a = look.CreateLook(l);
                    Response.Redirect("lookdv.aspx");
                }
                else
                {
                    Response.Write("<script>alert('视频格式不正确,目前只支持MP4或者ogg,或者webm')</script>");

                }

            }

 

五、当前端传过来的数据不正确时,弹出提示并且中止当前操作。

Response.Write("<script>alert('视频格式不正确,目前只支持MP4或者ogg,或者webm')</script>");

六、判断不等于null或者“”

!string.IsNullOrEmpty(对象名);

七、多条件查询:多条件查询一般使用linq语句,或者使用ado拼接字符串的形式

//先查询出所有的
            var temp = this.CurrentDBSession.UserInfoDal.LoadEntities(c=>c.DelFlag==delFlag);
            //根据用户名来搜索
            if (!string.IsNullOrEmpty(userInfoSearch.UserName))
            {
                temp = temp.Where<UserInfo>(u=>u.UName.Contains(userInfoSearch.UserName));
            }
            //根据第二个条件查询
            if (!string.IsNullOrEmpty(userInfoSearch.UserRemark))
            {
                temp = temp.Where<UserInfo>(u=>u.Remark.Contains(userInfoSearch.UserRemark));
            }
            userInfoSearch.TotalCount = temp.Count();
            return temp.OrderBy<UserInfo, int>(u => u.ID).Skip<UserInfo>((userInfoSearch.PageIndex - 1) * userInfoSearch.PageSize).Take<UserInfo>(userInfoSearch.PageSize);
               

 

转载于:https://www.cnblogs.com/wangjinya/p/11534864.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值