i have a gridview in my page and a datatable with 1000 rows in it .now i can bind gridview with datatable intwo different ways
bind datatable directly to gridview.
create another datatable with first ten rows and bind it to grid. on the next page request bind next 10 rows to gridview.
now my question is, does my second aproach really help me to improve perfomance of the page?
There are two ways to improve the performance in this case:
Enable paging in your GridView
Advantage: easy to implement, you don't need to change your DataSource
Disadvantage: You need to select all records from dbms
Page the DataSource itself(f.e. SQL-Server)
Advantage: Very fast and scalable
Disadvantage: More time-consuming to implement
With only 1000 rows i would recommend to enable paging in GridView.
Related
Suppose i have many dropdownlist in my aspx page and every dropdownlist is connected to database.
So what approach that i uses for the page_load.
Any Suggestion?
I am using ASP.Net C# with SQL Server 2008.
Depending on your requirements, I can think of different ways to improve the page load performance
If values in your dropdownlists do not matter on the initial page state, you can defer binding of the controls
If there are a lot items in each dropdownlist you can make use of autocomplete or load-on-demand
Output Cache
On the data side, you can use sqlcachedependency for data that do not change that often
If dropdownlists does not depends on other dropdownlists selected value then Best way as per my suggestion is that you create One stored procedure with All select querys for binding dropdownlist and from codebehind fill it into dataset then bind datatable in dataset to appropriate dropdownlist.
Its just my suggestion because as per what i know is store procedure are faster and in this way you only need to call one store procedure.
I want to add paging option for my datagridview. I have a datatable that fetch records from the xml file and bind it in datagridview. Xml contains so many records that are why I want to add paging option in datagridview in C #win forms.
Please help how I can achieve this task without using data adapter.
Thanks.
Page it manually. Create another DataTable with same scheme and copy one page of rows to it, at the times you require.
Of course, that is one option for doing it.
I have a gridview and sqldatasource.
I want to display in a label, the number of rows from the gridview which contains a certain value in one of the columns (in the form_load event)
I thought about looping through all columns of the gridview but it will take a lot of time for this and maybe there's another way of doing this.
Can someone help me finding the "other way"?
Thanks,
Best solution would be to let the database handle filtering - you'll get much better performance that way than looping over the data on application server.
Perhaps create another SqlDataSource with an SQL statement containing appropriate WHERE condition and bind it to your label?
I have a repository that contains all of my LINQ queries for this project that I am working on. I am able to get the LINQ results to a DataTable and bind that to a gridview for displaying the data. Now I need to make the gridview sortable. I have set AllowSorting="true" and I have the OnSort event handled in a routine in the codebehind. The program makes it into the sorting routine just fine.
Is manual sort my only option or is there an easier way to sort the gridview in the OnSort handler?
If you bind the GridView to a DataSourceControl then the sorting is taken care of for you. Otherwise you're stuck with doing it manually.
I ended up solving this problem using this example from MSDN and attaching my own datatable, which was acquired through a LINQ Query in my repository.
I have confusion about GridView in ASP.NET.
How does the GridView exactly work?
I mean when we bind data to gridview with 100 records through GridView1.DataBind();
I have set Pageindexchanging Event and I set the Pagesize = "40" and AllowPaging="True" Then....
Now the interesting part is begins What happens when i Click on next page index of GridView is it. Once again go to the database and fetch the data.. or gridview creates its own dataset and fetch data from that dataset or anything different than this...
And one more thing is how the Sorting works in GridView?
The simple answer is yes, the GridView is simply a view placed over a DataGrid, and all the parameters specified affect how the GridView is rendered for the user. Since we're dealing with the stateless web, you will have to rebind the data.
One trick for this is that if your dataset isn't too large, you can store the DataTable in the user's session and simply retrieve it from there, saving a trip to the database. If you are dealing with a large amount of data, then you'll want to look into options for having your SQL queries function in a "paged" format so you only retrieve the rows you intend to display.
With Paging and Sorting, they serve as an event to respond to in which you resort your data and rebind to the grid for presentation.
The advantage of the GridView is that you do have a central object with a lot of functionality built in that you can use for rapid deployment. When you get a hand of how the sorting, paging, row commands, and other things work, you can do some really great things in a small amount of code.
It depends what your data source is, if your datasource supports paging, then it will fetch only the records it needs to show that page, if it does not, it will get all the records and discard the one you don't want.
For both examples, it will talk to the datasource everytime you change page.
See here for more details:
http://msdn.microsoft.com/en-us/library/5aw1xfh3.aspx