开发者

Which control to design an asp.net page with sql?

开发者 https://www.devze.com 2022-12-10 21:56 出处:网络
I still have loads to learn. At the moment I have stored procedures, and a gridview bound to them. It works, but I want to learn new and better ways of doing things.

I still have loads to learn. At the moment I have stored procedures, and a gridview bound to them. It works, but I want to learn new and better ways of doing things.

I discovered I should be using ROW_NUMBER() to help keep my queries relevent to what fits in the paged g开发者_C百科ridview, which I am going to be implementing.

But what IS the best, coolest, neatest way to query a database to get say, customer information (name, email, phone) based on filters (age, partial name, gender) and display it on the screen?

Ideally I want it to be super userfriendly, with sorting and paging, and I want to be able to add buttons like 'View customer profile' or 'E-mail customer'.

I don't want to spend -years- developing each page though...so doing it all by hand is probably out.

Is gridview the way, or is there another control/method? Is there a guide on how to do this the right way?

I'm still fairly new to asp.net but I am getting there. It just seems like everything is an uphill struggle though.


Gridview seems like the best answer, in fact providing a quick means for CRUD operations is one of its main strengths.

Don't worry about the struggle with ASP.NET... when I moved from PHP to ASP.NET it took me a long time to get my head around web forms, and now Im about to go through it all again with ASP.NET MVC... you'll eventually get it.

Tip: Research "DataKeys" - this essentially allows you to set your gridview to identify its rows based on the column you specify as part of the datasource as shown below:

GridViewProducts.DataSource = t; // t is a datatable in this example.
GridViewProducts.DataKeyNames = new string[] { "ProductID" };
GridViewProducts.DataBind();

The easiest for me to explain this is as if the gridview is generating another column (which is invisible) but stores the ProductID for each row, just like the 'Product' table has a 'ProductID' column (its the same column you would use).

Eventually when you peform a UPDATE/DELETE on a row you'll want to know what the ProductID is, to obtain this you would simply use the following code inside the Gridviews RowUpdating and RowDeleting handlers:

    protected void GridviewProducts_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
string ProductID= GridviewProduct.DataKeys[e.RowIndex].Value.ToString();
// do update and pass through ProductID as a parameter.
}


For fastest way, you can also have a look at ADO.NET Entity Framework. Also look at these videos to know how easily you can achieve filtering.


You could have a look at something like jqGrid with a webservice on the back end to provide the data. It works quite nicely with MVC - Phil Haacks blog has some good samples.


I'd recommend taking a look Here from the MVC contrib guys. They do lots of cool stuff which can be added to MVC .Net Apps, includes paging and sorting

As for database connectivity to your source grid, consider nHibernate, with Fluent nHibernate (if your a lambdas kinda person). Gives you strongly typed sql generation, with intellisense in VS...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号