Limiting the number of records in a grid view - asp.net

Im working on a grid view in asp.net mvc 3 and I need to limit the number of record that will display in my grid(not per page). Is there a way I can do that??. Thanx in advance.

What are you using? Which GridView? It's really tough to help you whithout any detail information. But anyway, I'll try...
IMHO I wouldn't limit the number of records in the view, I would do this on the database query or whereever you get your data!
If you want to set a "JustShowMeXRecords" then put a TextBox or DropDown to your view and give this value to your controller.
If you want to have paging on your grid you can use in example this NuGet Package (http://nuget.org/List/Packages/PagedList). I use it in every project.
It has a static ans dynamic way to get this done.

Related

Load data in DropdownList by category wise

in my ASP.net web application i want load in dropdownlist box by category wise like below screenshot.. How can i do it??
I gonna use two table in DB
One is to Store Available Course
Second Table is Number of Degree like below
you can simplify using optGroup in dropdown...
please follow below link it might be useful for resolve your problem..
Group options for Asp.Net DropDownList
Enjoy coding....

thoughts on asp.net grid controls

All, I am creating a web application and I need to give users the ability to add/edit/delete records in a grid type control. I can't use 3rd party controls so I am restricted to just whats in the box for asp.net (datagrid or gridview) or creating my own. Any thoughts on the best direction to go in. I'd like to keep the complexity level at a dull roar :)
thanks in advance
daniel
You should definitely use edit and insert templates. All you have to do is give the button/link the command name such as insert/delete/update and you can allow the Grid to do most of all the work.
Check out this link
I think you'll learn to love the gridviews because they are pretty powerful.
Gridviews have different item templates that you can use for editing and inserting data. That'd be an easy way to go about it.
As long as you set your datakeyid property to the primary key in the database, you should be able to make template fields based off of whether or not you're editing or inserting data. The command name of the button you use to fire the event will handle the statements required for updating/inserting data.
This is a good site for some examples.
the out of the box grid is not too bad.
Here are a few links on master detail records in asp.net this should get you started on the CRUD opperations.
http://www.exforsys.com/tutorials/asp.net-2.0/displaying-master-detail-data-on-the-same-page.html http://msdn.microsoft.com/en-us/library/aa581796.aspx
http://www.bing.com/search?q=asp.net+master+detail
this is the best site for what you are after
www.Asp.Net
Data Access Tutorials controls
Master/Detail Using a Selectable
Master GridView with a Details
DetailView
Using TemplateFields in the GridView
Control
Others
Beginners Guide to the GridView
Control
The GridView Control
IN-DEPTH LOOK AT THE GRIDVIEW CONTROL

how to dynamically generate page numbers and only load the corresponding page in the grid?

I need to load data in the gridview dynamically. That is when the user clicks the page number 2 then those records only has to be displayed.. I made a stored proc to return only those records whose page number is sent.. It will also return me the number of records too.. Now i want to create a placeholder which will create the page number buttons dynamically based on the number of records. Could anyone help me with the placeholder code.. ??
You need to use ObjectDataSource for custom paging in GridView.
Check these articles:
https://web.archive.org/web/20210510021915/http://aspnet.4guysfromrolla.com/articles/031506-1.aspx
If you love AJAX, give this a try:
http://dotnetslackers.com/articles/ajax/ASPNETAjaxGridAndPager.aspx
Quote from the page:
Paging
When working with large tables we
often required to use paging. Although
the DataGrid/GridView has built-in
support for paging they are pretty
much useless. Most developers often
refuse to use the built-in
functionality and use their own custom
logic which usually takes a start
index, page size and other additional
parameters and in turn returns only
the paged records with the total
number of records.
There are enough codes on the page to help you start the balll rolling.
i suggest you to use DataGrid instead. DataGrid has paging property

What control should I use for showing "Featured Products" on my ASP.net Website?

I have various SQL tables and my use case is:
I'll choose 5 Products at random and they'll show in X control (don't know what to use here).
I know I'll have to use SQL and pull the product information using the ProductID as the hook to fish out every other information.
What Control should I use?
---If you want to show random product, then Adrotator is the best choice
---If you are getting product randomly from DB then Repeater or datalist could be the best choice
Depends how you want do display it.
Maybe a Repeater and ObjectDataSource will be useful, depending on your ORM.
Maybe a DataList, maybe a Repeater. explain more about what you want to show.
Two possibilities spring to my half-asleep mind.
the first would be to use a ListView or Repeater and have it themed out appropriately.
The second possibility would be to create a user control that displays the way you want, and then instantiate 5 instances on the web page.
I would make a user control that would take an array of ids as a property. Encapsulated in the user control would be everything you need to do to display your products. This would probably be an array of panels with images and labels.

ASP.Net: How to do pagination with a Repeater?

I'm using the Repeater control on my site to display data from the database. I need to do pagination ("now displaying page 1 of 10", 10 items per page, etc) but I'm not sure I'm going about it the best way possible.
I know the Repeater control doesn't have any built-in pagination, so I'll have to make my own. Is there a way to tell the DataSource control to return rows 10-20 of a much larger result set? If not, how do I write that into a query (SQL Server 2005)? I'm currently using the TOP keyword to only return the first 10 rows, but I'm not sure how to display rows 10-20.
You have to use the PagedDataSource, it allows you to turn a standard data source into one that can be paged. Here's an example article
This isn't a way to page the data, but have you looked into the ListView control? It gives the flexibility of repeater / data list but with built in paging like the grid view.
And for paging in sql, you would want to do something like this
This was answered here.

Resources