Gridview Sorted Event - asp.net

I've very small question that drives me mad :)
I've a Gridview (bind from db nothing special there) and I use small function that runs on the griviewrows and sets .Visable to false in case they don't match search criterias. It works fine but when I try to sort the grid view (by clicking on the header) all the "hidden" rows shows up again.
I tried to use the "GridView_Sorted" event in order to run on the gridview and hide again but it doesn't seem to do anything. The select statement is stored procedure so I can't use filtering expressions.
My Question is - Is there a way to run the hiding function after the sort
(as "Occurs when the hyperlink to sort a column is clicked, but after the GridView control handles the sort operation." {http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorted.aspx} suggests )

The GridView's PreRender event should do the trick.
You could just walk GridView.Rows and apply your logic there... That way it's guaranteed to occur at the right time wether the sort happens or not.

How are you binding the data?
Maybe it would help only to bind the used data (rows) to the grid, because binding not displayed data is kind of an overhead.

Related

Kendo Grid: Prevent datasource refreshing on grid filtering

I got a grid displaying +- 4000 candidates. You can search and filter the grid by typing in a textbox. For each character typed there is a 1.5 second debounce before the grid refreshes/filters with the textbox content as a parameter.
On my local database this works like a charm. But on the live environment there is a big performance issue.
Each time the filter is applied, the Read action is called, all data is fetched and filtered. This means a new request to the server for every character typed.
What I want to achieve is that when filtering, the filtering happens on the data inside the grid, instead of refreshing/reloading the whole datasource on every filter.
How can this be achieved?
This can be simply achieved by setting serverFiltering in DataSource to false.
API Reference

ASP.NET DataGridView paging with server-sided paging

I am passing the PageNumber and PageSize to a stored procedure, which returns only that page of data. It also returns a record count what the total number of records would be if I returned all of them at once.
Generally, how do i hook this up to the DataGridView to enable paging?
It seems like the expectation is for the resultset to contain the complete dataset.
Many of the properties that I expect to be able to set, like RecordCount, appear to be read only.
Could someone give me general pointers?
I created a similar solution once, and adjusted a GridView (not sure if you mean a DataGrid or a GridView) to use server-side paging. The code is too much to post here and since there's no option for attachments here, you can download the code from http://www.raskenlund.com/downloads/GridView.zip
Check out the following article which describes the same thing:
http://www.highoncoding.com/Articles/210_GridView_Custom_Paging.aspx

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.

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.

how do I create an array or list of ASP.NET checkboxlists

I know how to use the checkboxlist in ASP.NET to display options retrieved from a database. What I don't know how to do is to make this 2-dimensional. That is, I need a list of checkboxlists where I don't know how long the list is; both dimensions of the checkboxlist will be determined by
list of people (pulled from database)
list of tasks (pulled from database)
and the user of the web page will click in column/row to specify which people will be assigned which tasks.
Right now I'm thinking that my only option is to brute-force it by creating a table and populate each cell with its own checkbox. (yuck)
Is there a more elegant way to create a 2-dimensional array of checkboxes with labels for both rows and columns?
I would use a repeater along with a checkboxlist. Depending on how your database is setup you could have each checkboxlist databound.
I've done this before and resorted to the brute-force method you suggest.
It's not as nasty as you'd think. Other solutions that were declarative and databound would likely be just as convoluted and confusing.
I use the ASPxGridView from DevExpress. It has a control column type of Selected (or something like that) which will display a checkbox in the column with the other column populated from your bound datasource. The User can select any rows desired by checking the checkbox on the row and you can get all the selected rows easily inot a collection to process. DevExpress components really do get rid of a lot of brute-force programming.
You can programmitaclly use a GridView control. It's inherently two-dimensional and you can use databound CheckBoxFields for it.
If you're looking for a quick and dirty way, you can use the AJAX Control Toolkit with the two controls and can populate one based on the other. If that's not what you're looking for, I'd do it the brute force way.

Resources