Improve ASP.NET page_load Performance - c#

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.

Related

Different SQL Datasource on Dropdownlist Selected Index Change

I have a Grid view and I want to use Two different Sql DataSources on Selecting different values from DropDownList i.e. On Selected Index Change.
Please help me How should I implement that???
I don't want to use Code behind to change the Data in Gridview....
Thanks in Advance
Without using code behind you cannot implement in this process so it is not possible

How can I access SqlDataSource already selected data, if it is bind to a GridView?

I have a GridView and a SqlDataSource. All binding done in aspx, works correctly and Select calls an SP with parameters.
Now I would like to access the bound data programmatically, in stuctured form, not parsing back it from the UI, using cells or .FindControl or other hacks. I also do not want to reselect the data using my SqlDataSource's Select.
I've debugged the code but can not find any structured data neither in my GridView variable neither in my SqlDataSource variable. Maybe I was browsing the wrong properties or a cast was missing.
Thx in advance
I don't think you can do that. When you bind the data from an SQL DataSource to a Gridview, it fetches the data to display and then that's it. It's gone.
When a GridView updates the data, it uses the key field ID and the text in the GridView to do it. There is no other DataTable or other structure behind the scenes.

Get the number of rows which contain a certain value in one of the columns and display the number in a label

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?

What is reason behind GridView in ASP.NET?

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

How to filter the following listboxes in asp.net?

I have 4 listboxes (lstStates, lstCounties, lstCities, and lstZipcodes). Here are a few constraints:
None of the listboxes are disabled.
Any listbox can be selected at anytime, meaning there is no specific order the user has to choose.
Filtering is forward and backwards. By this, I mean if a user selects a state from lstStates, it will filter lstCounties, lstCities, and lstZipcodes. If a user selects a zipcode from lstZipcodes, it will filter lstCities, lstCounties, and lstStates.
The listboxes allow multiple selections.
Each listbox is bound to a datatable to get its initial data. The datatable is retrieved from a sqlserver stored procedure. Each listbox has its own stored procedure, for example, lstStates has one called GetStates which returns one column (State) and the ListBoxes DataValueField and DataTextField are both set to State. Similar to lstStates, lstCities is bound to a datatable which gets one column from a GetCities stored proc which is city.
Another thing I want to point out is that I am connecting an ObjectDataSource to get the datatable.
Already been asked: What is the most efficient way to filter listboxes based on selections of another in c#?
[edit]
OK, what you need to do is add an event to each [myListbox]_SelectedIndexChanged event. When the selection is changed you'll need to refresh all the other listboxes based on those selections. I assume that this will need to be handled by the database, since linking States to ZipCodes any other way would be ugly. So presumably your data for States<-->Zips<-->Counties relationships is in your db somewhere.
So you'll need to have procs in your db (or LINQ middle layer) that get States by Zips and so on. On each selection changed event, send the new selection back to the db sproc and then rebind the listbox based on the return data. You should be able to make one sproc for each one that returns all states if no zip is passed in and so on.
[/edit]
To clarify, on your initial load of the page, you are loading ALL zipcodes, ALL cities, ALL states and ALL countries?
This seems a bit cumbersome to me. This is the type of requirement I would question. (Granted I don't know that you didn't already question it or that some good answer came from it).
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "bab", "CacheItems();", true);
var ddlText, ddlValue, ddl, lblMesg;
function CacheItems() {
ddlText = new Array();
ddlValue = new Array();
ddl = document.getElementById("");
for (var i = 0; i

Categories