Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Deepa 14 posts 71 karma points
    May 21, 2015 @ 14:31
    Deepa
    0

    GridView with paging

     

    I am using MVC.In my website i need to show a gridview with paging that shows datafrom database.Could you please help me steps to create a gridview like this .

  • Mehul Gajjar 48 posts 172 karma points
    May 21, 2015 @ 14:47
    Mehul Gajjar
    0

    Hi Deepa,

    kindly look at below url , this is the good example of mcv grid with paging

    http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

    Hope it will help you.

    Regards,

    Mehul Gajjar.

  • Deepa 14 posts 71 karma points
    May 21, 2015 @ 14:50
    Deepa
    0

    I need the steps for creating this grid in Umbraco.Is it need to create a webgrid in a partial view

  • Mehul Gajjar 48 posts 172 karma points
    May 21, 2015 @ 15:01
    Mehul Gajjar
    0

    Hi Deepa,

    yes you need to create a webgrid in a partial view.

    and if you need this in umbraco back office then you have to make a custom property editor.

    Regards,

    Mehul Gajjar.

  • Deepa 14 posts 71 karma points
    May 21, 2015 @ 15:12
    Deepa
    0

    This is my partial view

     

     

      @{
            UMMbr.Model.SOTI product = new UMMbr.Model.SOTI();
            var db = ApplicationContext.Current.DatabaseContext.Database;
            // Fetch a collection of contacts from the db.
            var listOfContacs = db.Fetch<UMMbr.Model.SOTI>(new Umbraco.Core.Persistence.Sql().Select("*").From("SOTI"));

        }
      
        @{
            var grid = new WebGrid(listOfContacs, canPage: true, rowsPerPage: 2, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
            grid.Pager(WebGridPagerModes.NextPrevious);}
        <div id="gridContent">
            @grid.GetHtml(tableStyle: "webGrid",
                    headerStyle: "header",
                    alternatingRowStyle: "alt",
                    selectedRowStyle: "select",
                    columns: grid.Columns(
                                      grid.Column("Title", "Title"),
                                      grid.Column("Quarter", " Quarter"),
                                      grid.Column("Summary", "Summary", style: "description"),
                                               grid.Column("Link", "Link")
             ))
            @if (grid.HasSelection)
            {
                product = (UMMbr.Model.SOTI)grid.Rows[grid.SelectedIndex].Value;
                <b>Id</b> @product.Title<br />
                <b>Name</b>  @product.Quarter<br />
                <b>Description</b> @product.Summary<br />
                <b>Quantity</b> @product.Link<br />
            }

     

    But paging is not working .

  • Deepa 14 posts 71 karma points
    May 21, 2015 @ 15:13
    Deepa
    0

    How can i get data from controller to webgrid?.

  • Mehul Gajjar 48 posts 172 karma points
    May 22, 2015 @ 06:58
    Mehul Gajjar
    0

    Hi Deepa,

    For getting a data from controller you have to pass model to your partial view at the time of calling

    you can access your model data after inherit using @import YOURNAME_SPACE.YOUR_MODEL in your partial view.

    @model YOURNAME_SPACE.YOUR_MODEL
    @using System.Web.Helpers;
    

    Also see below example

    https://our.umbraco.org/documentation/Reference/Mvc/partial-views

    https://our.umbraco.org/documentation/Reference/Templating/Mvc/child-actions#RenderingaChildAction

    You can pass parameters in your partial view like this:

    Partial View Macro

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        Html.RenderPartial(
            "~/Views/Partials/YourPartial.cshtml",
            Model.Content,
            new ViewDataDictionary(this.ViewData) {
                { "FirstParam", "something" },
                { "SecondParam", true }
            }
        );
    }
    

    Partial View

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    
    @{
    var FirstParam= (string)ViewData["FirstParam"];
    var SecondParam=  (bool)ViewData["SecondParam"];
    }
    

    This partial view is strongly typed and is passing the current page as the Model, so you can access properites like this:

    Model.GetPropertyValue<string>("myprop")
    

    Hope that's helpful

    Regards

    Mehul Gajjar.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies