I am keeping DataTable in session variable.
A GridView having template column checkbox with autopostback set to true.
oncheckchange event of checkbox is tracked to delete or add rows in session DataTable.
Application opens multiple instances of same page and respective GridView on page is source for adding or deleting rows in (one for all) session DataTable.
Now problem is that I cannot click fast on checboxes in a gridview.
Apparently it look like server side process of updating session table is very
slow. Sometimes cached clicks come into action quite slowly. Please guide how to maintain session DataTable efficiently?
Note:
I have checkbox in the header row of every GridView as well, which checks and un-checks every row present in Gridview.
Related
asp c#
i have a page where user selects an item and its quantity to purchase and next item and so on
all items selected are filled in datatable and shown in gridview
at the end of selecting items
when user clicks process button
i want to insert all items and its quantities in database
on pageload a datatable is empty
on btn_Select_Click i hv filled in few rows
on btn_Process_Click i want to loop through these rows and insert records in db for each row
but it returns zero rows
Your question is a little vague. "but it returns zero rows"... I'm guessing that what you mean is, that in the click handler for your button, when you access your grid object, it has no rows in it?
Remember that each load of the page creates a whole set of brand new webcontrols. Webcontrol objects are not persisted in memory to be reused on each hit to the page.
If you want the same rows available on this new page that is being rendered after the button click, you have to re-bind your grid. I'm guessing that isn't happening in your code.
So I'm currently working with a C# ASP page in which I have a DropDownList and a GridView. I'm initializing both the GridView and the DropDownList (Along with their connected data sources) in the PageLoad event.
I've got the DropDownList set to AutoPostback=true. I'm changing the select statement for the GridView in the DropDownList_SelectedIndexChanged event. The end result is that the page loads again and then the select statement is changed, by which point the GridView has already loaded again. This basically means that it the GridView changes take two page refreshes to update.
Is there a way to avoid having to refresh the page twice? I tried simply updating the DataSource and the GridView in the Page_LoadComplete function instead but by that point it was too late to update the page this time around, meaning it still required another refresh.
So you may try this in your page load....
if(!IsPostBack)
{
// only then bind your grid View...
}
and in your DDL's selectedindex changed event bind your grid to what ever select result set you may want to bind to...
what this will do is, your grid view bind code will get executed only for the first time in your page load event...and on any subsequent postbacks you may cause with your dropdown...you can bind your gridview in the selected index changed event...this will avoid binding your gridview twice...
I've got a user modification page, that displays a list of reports a user has access to using a GridView object.
What I want to do is, if someone makes a bunch of changes to a users page, but then clicks cancel, all changes that are made will be undone.
My main issue here is the GridView, which has add/delete/modify buttons, tied to a separate table.
So if I open my own page, add a new report to the gridview, then hit cancel, I don't want that report to be saved to my account..
Likewise, if I delete a record, and then hit cancel, the record is not deleted.
What is the best way to do this?
You need to maintain this in the datatable and put this in a Session variable and bind your gridview to your datatable that is in the session. So once you are finished with the changes and want to submit the changes in the DB, you have to play with Datatable Row State, from which you can find which row is added and which one is Deleted or Modified.
Have a look at this article to understand Datatable Row state
system.data.datarow.rowstate
In such case you mustn't bind GridView to the real datasource (Entity framework). If you do it changes will be written to the database and you will have very hard time to roll them back. GridView must work with temporary data stored for example in the session and only after commiting changes (Save button on the page) the data will be written to the database by EF.
i have a webpage that loads data into a gridview and refreshes the gridview every few seconds. I do this via a asp:Timer which runs a C# function every few seconds to requery the database and databind the gridview.
I also have a few dropdown lists to filter data from the gridview. These dropdown lists get their data from the same dataset as the gridview (e.g. if the gridview shows the stats of all apples being plucked from trees, then the list may contain e.g. all distinct apple types). How i refresh these dropdown lists is again to requery the dataset and reset the selected index to be one selected at time of refresh. So this causes a problem where the timer is up when the dropdown list is open - the index on the dropdown list is selected and refreshes the gridview, the dropdown list also refreshes with the current selected index and closes.
So the question i have how to disable my timer refresh from going off while the dropdown lists are active - or maybe how do i do this better?
edit: forgot to mention that i'm using ajax / UpdatePanel for the refresh
The first thing you need to do is define some event to capture when the dropdown is open. I dont think there is one, but you could use focus() events ... maybe.
Then when the dropdown list is open, you need to disable the timer client-side. This article explains it (though using a checkbox)
http://weblogs.asp.net/aboschin/archive/2007/10/06/ajax-how-to-control-an-lt-asp-timer-gt-on-client-side.aspx
I've got a bit of an chicken and an egg.
I need to bind a gridview to a set of database values. The gridview is dynamic and the columns, cells are created at run time.
As such, I need to re-bind the grid on every postback in the pre-init, init events after very post back.
However, the data used to populate the grid uses a value from a dropdown box on the same page. As such, the value of dropdown is not accessible through viewstate until after the init event (i.e. the selected index is always the first item in the list until after on init).
How can I get access to the value of the drop down in time to rebind the grid before the pageload event?
If the Gridview always has the same number of columns, you could have the dynamic query generate column names as aliases, and then just rebind the Gridview on dropdown change?
you can use and HtmlHidden control for store the value you need. It doesn't depend by the viewstate and it's available into the page init