• HTML FORM


    @{
        var db = Database.Open("WebPagesMovies") ;
        var selectCommand = "SELECT * FROM Movies";
        var searchTerm = "";

        if(!Request.QueryString["searchGenre"].IsEmpty() ) {
            selectCommand = "SELECT * FROM Movies WHERE Genre = @0";
            searchTerm = Request.QueryString["searchGenre"];
        }

        if(!Request.QueryString["searchTitle"].IsEmpty() ) {
            selectCommand = "SELECT * FROM Movies WHERE Title LIKE @0";
            searchTerm = "%" + Request["searchTitle"] + "%";
        }

        var selectedData = db.Query(selectCommand, searchTerm);
        var grid = new WebGrid(source: selectedData, defaultSort: "Genre", rowsPerPage:3);
    }
    <!DOCTYPE html>
    <htmllang="en">
     
    <head>
       
    <metacharset="utf-8"/>
       
    <title>Movies</title>
       
    <styletype="text/css">
         
    .grid {margin:4px;border-collapse: collapse;width:600px;}
         
    .grid th,.grid td {border:1px solid #C0C0C0;padding:5px;}
         
    .head {background-color:#E8E8E8;font-weight: bold;color:#FFF;}
         
    .alt {background-color:#E8E8E8;color:#000;}
       
    </style>
     
    </head>
     
    <body>
       
    <h1>Movies</h1>
         
    <formmethod="get">
           
    <div>
           
    <labelfor="searchGenre">Genre to look for:</label>
           
    <inputtype="text"name="searchGenre"value="@Request.QueryString["searchGenre"]"/>
           
    <inputtype="Submit"value="Search Genre"/><br/>
            (Leave blank to list all movies.)
    <br/>
           
    </div>

           
    <div>
             
    <labelfor="SearchTitle">Movie title contains the following:</label>
             
    <inputtype="text"name="searchTitle"value="@Request.QueryString["searchTitle"]"/>
             
    <inputtype="Submit"value="Search Title"/><br/>
           
    </div>
         
    </form>

       
    <div>
          @grid.GetHtml(
            tableStyle: "grid",
            headerStyle: "head",
            alternatingRowStyle: "alt",
            columns: grid.Columns(
              grid.Column("Title"),
              grid.Column("Genre"),
              grid.Column("Year")
            )
          )
       
    </div>
     
    </body>
    </html>

    其中的:

    var selectedData = db.Query(selectCommand, searchTerm);

    是查询语句,searchterm是参数

     selectCommand = "SELECT * FROM Movies WHERE Title LIKE @0";

    参数依次为@0,@1

    var grid = new WebGrid(source: selectedData, defaultSort: "Genre", rowsPerPage:3);

    defaultSort 默认排序方式

  • 相关阅读:
    Spring事务管理学习笔记
    写给初学前端工程师的一封信
    angularjs 自定义指令弹窗
    ng-if和ng-show的区别
    前端遇到的一些坑
    浏览器样式兼容总结
    百分比控制表格列宽,不起效
    ng-model 将时间戳转换为标准时间
    使用git和sourcetree提交代码的一些问题
    本地运行angularjs应用,提示出现跨域问题
  • 原文地址:https://www.cnblogs.com/littleebeer/p/3365595.html
Copyright © 2020-2023  润新知