• 网站开发常用功能


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

    <a style="float:right;" onclick="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;" onclick="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" onclick="window.location='Register.aspx'">注册</button>
                        <button type="button" class="navbar-right btn btn-success navbar-btn u-mr--10" onclick="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);
                   

     八、将数据追加到标签上

    $.post("/Admin/LoginLogInfo/GetSchool", {}, function (data) {
                    for (i = 0; i < data.length; i++) {
                        var option = "<option value='" + i + "'>" + data[i] + "</option>";
                        $("#SchoolId").append(option);
                        layui.form.render("select");
                    }
                })
  • 相关阅读:
    ASP.NET Core新书终于上市,完成今年一个目标,赠书活动
    .NET 5.0 RC2 发布,正式版即将在 11 月 .NET Conf 大会上发布
    .NET Standard 来日苦短去日长
    [C#.NET 拾遗补漏]09:数据标注与数据校验
    几个超级实用但很少人知道的 VS 技巧[更新]
    .NET 5 中 Target Framework 详解
    .NET 5.0 RC1 发布,离正式版发布仅剩两个版本
    Git 实用操作:撤销 Commit 提交(动图讲解)
    Git 实用操作:重写 Commit 历史
    [C#.NET 拾遗补漏]08:强大的LINQ
  • 原文地址:https://www.cnblogs.com/wangjinya/p/11534864.html
Copyright © 2020-2023  润新知