ASP.net disable refresh when dropdownlist is open - c#

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

Related

ComboBox Event works with ListBox but not with GridView

The function should be simple:
I select an item, which is added to a list, then i manage that item using the list.
As first try i put some buttons next to the listbox and it worked fine.
But the objective is to add two buttons in each row, so i replaced the listbox with a gridview.
What's the problem? The event SelectedIndexChanged of the ComboBox (which is used to add the item to the list) does trigger once but not the second time.
The page correctly goes through page load, but the combobox's event is ignored.
Code here:
https://pastebin.com/Bmg2qjTf
I think i must say the combobox is filled using an SQL: the first time the SQL Query is executed and applied to the ComboBox's DataSource and in a Session, on PostBacks instead it gets refilled thru the Session variable.
Solution: Adding a txtNumSpedizione.Text = "";
Troubleshooting:
I tried to make both (listbox and gridview) work at the same time and this way it worked, also the gridview was getting all the selections.
So i figured out the difference between before and after was in the Text field "reset".

asp c# looping through dynamic datatable

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.

Timing a gridView Update in C#

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...

asp.net using c# DropDownList item not selected

ASP.NET using C#:
I've got a DropdownList and a Button.
In Page_Load I fill the DropdownList manually via SQL-Query with some items from the database.
After click on the button I want to Alert the selected item of the list but every time the first item alerts instead of the selected item.
So simple, but what am I doing wrong?
Without your code it's hard to say, but I'm guessing on your page load, your reloading your dropdownlist, which is removing the selected item, and giving you the first item every time.
If this is the case, check for the request being a postback, and don't repopulate the drop down list.
when click on button happen postback and run page_load and fill dropdown list agin then show first item that selected.
if (!IsPostBack)
{
//fill the dropdownlist
}

Dynamic gridview based on dropdown

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

Categories