Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends...

I'm using Visual Web Developer 2008 express.
I'm novice to MVC2 .net c#. I'm bit confuse to use or how can I use Gridview in my .aspx page that resides in View folder in my Solution Explorer.

I'm using MYSQL and don't know how to use ado.net entity frame work for data base connectivity with MYSQL.

Please guide me...Can I use asp.net controls in mvc2.net and MYSQL in MVC2.net

Thanks :)
Posted

why don't you try jqGrid instead of gridview like the one shown :
http://haacked.com/archive/2009/04/13/using-jquery-grid-with-asp.net-mvc.aspx[^]

and for learning entity framework refer.
http://si.ua.es/en/documentacion/asp-net-mvc-2/ado-net-entity-framework/ado-net-entity-framework.html[^]
this might help you.
 
Share this answer
 
v2
Comments
Manish Kumar Namdev 7-Mar-12 4:01am    
Thanks for your reply.
I go with your given links. And revert back.
You don't need to use entity framework to use MVC - you can use whatever data strategy you like. In your case, just make sure you've got the MySql.Net Connector[^]

As far as using a standard ASP.Net Gridview[^], you wouldn't use this in your MVC views. Instead, you should be returning data you want displayed in a Grid in your Model - this will usually be an Enumerable list of objects e.g.


C#
public class GridDataModel
{
    public int Id { get; set; }
    public string Description { get; set; }
    public System.DateTime ItemDate { get; set; }
    public decimal SpentValue { get; set; }
}

public class HomeController : Controller
{
    public ActionResult Index()
    {
        var model = GetHomePageModel();
        return View(model);
    }

    private System.Collections.Generic.List<GridDataModel> GetHomePageModel()
    {
        var model = new System.Collections.Generic.List<GridDataModel>();

        for (int i = 0; i < 30; i++)
        {
            var item = new GridDataModel
            {
                Id = i,
                Description = string.Format("Item number {0}", i),
                ItemDate = System.DateTime.Today,
                SpentValue = (100 * i)
            };
            model.Add(item);                
        }
        return model;
    }
}


In your view, you set the view to expect data of this type by specifying the model (Razor syntax) and render your view however you like. You could simply render a table and use jQuery DataTables[^] to make it into a grid.

HTML
@model List<GridDataModel>
@{
    Layout = "SomeMasterLayout.cshtml";
}
<div class="yourpage">
    <div class="grid-data">
        @foreach (var item in Model)
        {

        }
    </div>
</div>


Or, you could look at something like Telerik MVC Controls [^] which would allow you to do something like this

C#
@(Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(o => o.Id).Width(100);
            columns.Bound(o => o.Description).Width(200);
            columns.Bound(o => o.ItemDate).Format("{0:MM/dd/yyyy}").Width(120);
            columns.Bound(o => o.SpentValue);
        })
)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900