Need suggestions Asp.Net DropDown LIist Filtering - asp.net

3262 Points
662 Posts
Need suggestions
17 hours, 13 minutes ago|LINK
I have an insert data page, having a drop down on the page items are filling from SQL Data Source (using code behind)
I need to apply some filter to chop out certain values from Drop Down (user will select some radio buttons and then
apply the filter, when filter applies, it will remove the unwanted items from drop down)
Now I dont know what is best procedure, I have done:
1) Using AJAX update panel, so when the user clicks on Apply, I am re-generating query and re-binding the drop down list)
so it involves server round trip, every time user clicks on apply button.
The best thing about this is, if user wants to insert records one by one, then user does not have to apply filter agian and again
(once applied it will only show the filtered values after each record insertion)
2) Using client side javascript i have achieved the same but big problem here is that
once a record is inserted, the page will refresh, and thus the drop down will show all the UN-Filtered values again
I need suggestions on which techinque I should follow in this regard, plz help

Using ajax is the best option, but in sql you create a stored procedure, so that it might reduce the time of regenerating query.

Related

how to reduce web page size with many select controls

I'm working on an asp.net application that allows the user to update data for a series of days. The data is presented as a table:
Date - Active - Active Promotion
04/11/11 - yes - listbox with 360 entries
05/11/11- yes - listbox with 360 entries
06/11/11 - yes - listbox with 360 entries
...
04/02/12 - yes - listbox with 360 entries
Now, the table can have from 90-700 rows (eg allow entry for 90-700 days) and the select box has 360 entries (12,000 characters). So, for a 3 month display, I get the page size of 90 * 12,000 = 1MB and this increases to 8.4MB for a 2 year display.
I can see that the problem is the many repeated listbox . I have thought of the following approaches, perhaps people can suggest improvements or refinements:
Have each listbox populate itself when clicked (reduces initial page size but user may have to wait for drop down to populate)
Have one 'real' listbox and many 'fake' listbox . when the user clicks on a 'fake' listbox the 'real' listbox is then displayed, the selected value is then stored in a hidden field
get the client to cleanup the data so there aren't 300+ options in each box
If the options are the same for every listbox, I would definitely suggest auto-populate with javascript on clicking. I've used this solution before for exactly the same reason, and there is no perceptible delay in popping up the select list, and the original page loads way faster.
Also Firefox used to have a bug when handling lots of large select elements, and the javascript populate when necessary solution also sidestepped that.
I would go with something like the second option. What you can also do is to populate the first one initially, and then copy the contents to others using JavaScript.
But otherwise - seems you got some usability problems to solve, who's gonna use such monster forms!? :)
I would limit input to one month at a time and store it in memory until ready to complete the transaction back to the DB. I would also review choice of control for this, that is, instead of a listbox think of something more intuitive; possibly a calendar with text boxes - you could use tabs and move from one month to the next.

Two tables on one page Asp.Net

My project is in Asp.Net Webforms using C#.
On one of my web pages, I want to have two tables. One is going to be a summary table and the other a more detailed breakdown of the summary. When the user clicks on one of the rows of the summary table, I want the corresponding breakdown rows to appear in the breakdown table.
These tables can have anything between 60 and about 500 rows.
I have thought of two possible ways of doing this and I'm not sure which is best, or if there is another, better way of implementing this:
1) When a user clicks on one of the rows in the first table, a postback event happens, and the data for the second table is loaded from the code behind.
2) When the webpage is loaded for the first time, both tables are filled with all of the possible data, but all of the rows in the second table have the "display: none;" CSS attribute. When a user clicks on a summary row, the CSS of the corresponding breakdown rows is changed using JavaScript.
I'd go with your first thought and perhaps either
load the data for the second table through an AJAX request returning only row data in JSON (or maybe even the HTML for the table)
use an UpdatePanel
if the user only needs to view the data, I would go for the former, but if they need to edit the data in some way, I would probably choose the latter (even though I'm aware that UpdatePanels are effectively a full postback in async clothing, I feel their use can make the UI more fluid).
You could also make an AJAX call when the user clicks on a row in the summary table to return the data for the 2nd table.
second way no way, loading all of data and then hiding showing is not a good idea, it will be slow and if you add more functionality it will only get in your way...
I recommend this two approaches:
1)first table with pagination
click on row triggers ajax call to page method
page method return second table
here, you can see how to that:
http://encosia.com/2008/02/05/boost-aspnet-performance-with-deferred-content-loading/
2)using of uframe
http://labs.omaralzabir.com/UFrame2005/
cheers

Easiest method to build where clause from checked items in DataList of PreviousPage

I have a selection list that is generated dynamically, it lists a number of checkboxes that are based on an end-user editable table, as such I have no idea what data, or how much, might be contained in this table and how many checkboxes or what they might contain, other than the primary keys of the table.
The user will select the checks they wish to see, and then control is passed to another page via PostBackUrl. The second page has to figure out which records to show (build it's where clause) based on the checkboxes checked in the previous page.
So, my problem is several-fold. First, asp:CheckBoxes don't have values. This can be worked around by a number of methods. Right now, i'm using a placeholder and dynamically creating the checkboxes in the ItemDataBound event of the DataList. I set the ID to "CheckboxKey1Key2" (where Key1 and Key2 are the primary keys of the check items).
Second, I have to walk through the controls of the PreviousPage to dig out all these values. That in itself is also a pain, but doable.
Now, my thinking is to build the where clause of my Linq2Sql query based on the keys I got from decoding the checked checkbox names. This all seems like a lot of jumping through hoops for something that shouldn't be this difficult. Am I missing something? Does anyone have any better solutions?
Make a class with a structure for your values that will be useful and easy for you to use on the result page. Then when the user clicks whatever it is they click to go to the result page, loop through the DataList, create a collection from the checked items, and you will only need to grab one object instead of everything, when you need to format your query.
Then when you get to the result page, loop through the collection and build the query in the loop. Pretty easy and not much code.

Odd paging problem with DataGrid and sorting

I have a data table that is being filled by a stored procedure. I need to filter down the results some, so I get a data view from the default view and apply a row filter to it. I then bind this to my DataGrid. All is fine at this point. I see two pages (17 records with 10 per page). If i apply a sort to the grid though, it now shows 5 pages (58 records without the filter). I stepped through the code and it repopulates the data prior to running the sort. The repopulation is with with the filter in place and it counts 17 records, but shows 5 pages.
To make it even weirder, if I click on a page i know will be invalid, it runs the page change (which also repopulates the data) and this time it limits the pages to 2 and tells me i have an invalid page number!
Any ideas?
It was the custom control causing the problem. We have an AutoDataSource function that automatically pulls the data tables out of my view and sorts on them. I found a filter function in my grid that apply the filter, but only if applied before setting the datasource
Make sure to apply the sort to the default view and not the grid column directly.

Get Changed Rows of GridView ASP.Net

How Can I find all the rows that has been changed in gridview. I can not use Ajax in any form
First get the contents of your grid before it was changed (such as caching the results of the original gridview datasource binding). Then go through the dataset/datatable/however you want to store it, and compare the contents with the current rows of the gridview.
There's no real efficient way to do this, no method like GridView.GetAllChangedRows(). So, what you might do instead is keep a behind the scenes List that you add to each time a row is modified (use the RowUpdated method), then clear this list when needed.
It depends upon how many columns you want to edit in a row.
If you have only one editable column in a row then you can associate a javascript method with that control which you want to modify and in that method you can get a rowid which you can save in another hidden field and in server side you can get all rows whose ids are stored in hidden field.
If you have whole row editable in that case the best approach I think you should save the original data source somewhere and also set a javascript method with rowclick event to get rowid which user selects. Then when user clicks on submit button get all rows whose row ids are stored in hidden field then compare those with same rowid in datasource. This is the best approach from my point of you.
Let me give you an example, suppose there are 1000 rows in a grid and user clicks on only 180 rows. In that case we will compare only 180 rows and wont compare rest of the rows.
Please let me know if somebody has better idea then this.

Resources