There are two Comboboxs, one button, and a GridView in a page.
When I click the button, the selected items of the Comboboxs should be inserted to the GridView and at the same time updated in database.
When I click the button it should not perform a postback. Users should be able to add lots ot records when hitting the submit button.
Here is what you need to do:
Set a script function call in OnClientClick and return false from this method.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx
In this client method use JQuery AJAX to call a web method to update the db.
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Add a row to the table with jquery methods that manipulate DOM.
Add table row in jQuery
Of course you can use an UpdatePanel but you have to insert the combo and the grid inside, so this is not going to save you server CPU and traffic.
Related
I am working on asp.net web application.
I have to display data to the user in table format (it could be a table or gridview or something else ).
There is one column which has two signs plus and minus. I have to display data of n records, so there could be maximum n no. of rows. Rows will be created dynamically. Initally there will be only one row. User will fill details in first row and if he wants, When user clicks on plus sign, one row will be added below this row and if he clicks minus in a row that particular row will be deleted.
So I want this to be handled on client side not on server side and I dont want postback or page reload.
Is it possible by jquery, java script or ajax. Please suggest me how.
You can do this with a some AJAX, I prefer to use JQuery to streamline the process for me. When I do the same thing on my pages this is how I do it:
The page loads without the table.
The page (from the client) sends an AJAX request to the server for the table data.
The table data is returned and the table itself is built in javascript. This can be done by generating the table object or you can write the html yourself (that's how I do it).
I attach events to the two buttons, in your case a plus and a minus, that fires a javascript event.
The javascript event sends an AJAX request back to the server asking for a delete or new row.
The deleted row is either removed in javascript, or added in.
Now you can either request the data through AJAX and then build the table row yourself, or you can ask the server to send you the row pre formatted. Either way remember that these objects, the buttons and the table, will not be ASP.Net objects, will not be in Viewstate and will not persist through post backs so be prepared to rebuild this table each time you perform a post back.
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.
I'm using a dropdownlistfor that populates some data from the database, the idea is that i want that the default value of the dropdown, has to be editable.
So the user can submit one of the options that are populated from the database, or the default one modified
How can i make this?
You could use an onclick event on the first value that triggers a jquery pop-up with a textfield which could rewrite your first value of the dropdown on submit.
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 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