Saturday, 15 February 2014

c# - SqlDataSource_OnSelected: Get data (DataTable) without re-executing the query -


About 10 to achieve I have bound to a Gridwuv with a Skyuelditasor an SDL which is what the data again Takes seconds.

Apart from this, there is a "PageSizeControl" named UserControl, which hooks to the selected event of GridView's SqlDataSource. In this event, I need DataTable to create some settings of PageSizeControl.

Currently, I am doing it with the following code:

  protected void Ds_Selected (object sender, SqlDataSourceStatusEventArgs e) {SqlDataSourceView Disvi = (sender as SqlDataSourceView ); Dsv.Selected - = ds_Selected; DataTable DT = (dsv.Select (DataSourceSelectArguments.Empty) as DataView) .Table; Int iRowCount = dt.rows.Count; // Some bui-adaptations like visibility, text, ...}  

In the older versions we have e Affected Roses used. But applies to the values ​​stored in e.AffectedRows is not right when a filter Detasors and we have use-case where we do not need to count only line, but requires full Datatayl.

The problem is that. Select () DB-query is executed again and the other 10s

I also tried to turn caching on SqlDataSource to:

  EnableCaching = "true" CacheDuration = "infinite"  

But it was not useful for two reasons: 1. Unsolved event is not removed when cached data is received. 2. If the on-selected event has been removed (because the data has not been cached yet), then. Select () still executes the removal and takes 10s.

Does anyone have a clue how can I get the data without time-consuming query-time without re-execution ? Best choice will be in, but I am open for other suggestions.

I me sits an alternative got the solution that fit my needs I use event GridView.OnRowDataBound And first gets GridRow DataItem, which is datatable.

  Private databases oData = null; Protected void Gv_RowDataBound (object sender, GridViewRowEventArgs e) {if (Odata == null and amp; Ikrokdetaim! = Null) in Detaiv) Kro as {Odetta = (Ikrak Detatauv. }}  

This solution works, but it looks quite dirty and requires a gridview (which is not a problem in my case). I would be grateful for a more clean solution. After a long research with

UPDATE , I got the conclusion that it is not possible to get data on the unselected event. Even if caching is not enabled, because the cash is written after unsecured.

So the easiest way is to turn on the cache and call the SqlDataSource.Select (...) function where you need the data.

Another way to get data with SqlDataSource.Select (...) and then pairing the table in Control. But there are some disadvantages. For example: sorting on gridview and does not work outside the paging box, when a dataset is bound for data / cable.

And then another way is to look at the above example for GridView to remove the data from the control that it has been selected.


No comments:

Post a Comment