locked
How can I sorting movies into WebGrid in time? RRS feed

Answers

  • User-821857111 posted

    Add a new column to your Movies table called DateEntered and select datetime as the data type. Add some dates to the column against the existing movie entries. You are better off entering them as yyyy-mm-dd. Don't worry about how they appear in the database design tool. Then you can run your existing page as-is. The query includes all columns so your WebGrid should include the new column, so long as you haven't specified the columns to display. If you have, just add the new one:

    @grid.GetHtml(
        columns: grid.Columns(
            grid.Column("Title"),
            grid.Column("Genre"),
            grid.Column("Year"),
            grid.Column("DateEntered")
        )
    )



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 9, 2013 3:19 PM

All replies

  • User516094431 posted

    I have implement below example check this, it;s working perfect:

    DECLARE @tmp TABLE(MovieName VARCHAR(50), DateColumn DATETIME)

    INSERT INTO @tmp (MovieName, DateColumn)
    VALUES('Movie1',GETDATE())
    INSERT INTO @tmp (MovieName, DateColumn)
    VALUES('Movie2',GETDATE())
    INSERT INTO @tmp (MovieName, DateColumn)
    VALUES('Movie3',GETDATE())
    INSERT INTO @tmp (MovieName, DateColumn)
    VALUES('Movie4',GETDATE())

    INSERT INTO @tmp (MovieName, DateColumn)
    VALUES('Movie5','2013-07-08 16:01:53.547')
    INSERT INTO @tmp (MovieName, DateColumn)
    VALUES('Movie6','2013-07-08 16:01:53.547')

    SELECT t.MovieName, convert(varchar, CAST(t.DateColumn AS DATE), 104) AS MovieDate
    FROM @tmp t
    ORDER BY CAST(t.DateColumn AS DATE) DESC, t.MovieName

    Tuesday, July 9, 2013 8:06 AM
  • User1444407342 posted

    Thank you I try it.

    Tuesday, July 9, 2013 2:50 PM
  • User-821857111 posted

    Add a new column to your Movies table called DateEntered and select datetime as the data type. Add some dates to the column against the existing movie entries. You are better off entering them as yyyy-mm-dd. Don't worry about how they appear in the database design tool. Then you can run your existing page as-is. The query includes all columns so your WebGrid should include the new column, so long as you haven't specified the columns to display. If you have, just add the new one:

    @grid.GetHtml(
        columns: grid.Columns(
            grid.Column("Title"),
            grid.Column("Genre"),
            grid.Column("Year"),
            grid.Column("DateEntered")
        )
    )



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 9, 2013 3:19 PM
  • User1444407342 posted

    Ok , I understood, this is really simple thanks.

    Tuesday, July 9, 2013 4:18 PM
  • User1575937287 posted

    Hi filmobile,

    Do you mean that you want to get all the movies on some day such as Monday or 09.07.2013? If do, refer to bellow:

    First, add a textbox and a button to the page in order to tell the page the DateTime you want to research.

      <body>
            <h1>Movies</h1>
            <form method="post">         <div>
                    @grid.GetHtml(
               tableStyle: "grid",
               headerStyle: "head",
               alternatingRowStyle:"alt",
               columns:grid.Columns(
               grid.Column("Title"),
               grid.Column("Genre"),
               grid.Column("Year")                     
               ))
            </div>
                <div>
                  <input type="text" value="" name="sortTime" /> <input type="submit" value="Search"/>             </div>
                </form>
        </body>

    Then, add the Sql string and the grid bind  in the @{} block.

     if(IsPost)
        {
            selectedData = db.Query("select * from Movies where Year="+Request.Form["sortTime"].AsInt());         grid = new WebGrid(source:selectedData);     }

    Try it.

     

     

    Friday, July 12, 2013 3:20 AM