I use a GridView to represent data from a table in my DB.
the GridView has some template fields whose content are determined before displaying the Grid ( I use the RowDataBound event to determine content of template fields before displaying the GridView).
The page displays a list of records from the table records and then, the recording process starts. after the process is over, the template fields should be updated.
how do I automatically refresh the GridView after the process is finished ? it should be noted that the GridView is contained within an control and that I continuously poll the server using a Timer control that executes "GridView1.DataBind()" at the server level every 60 seconds.
since the GridView is inside an UpdatePanel, calling DataBind() method on it doesn't seem to call the RowDataBound event.
How can I solve this ?
Yes, thats enough to call the GridView1.DataBind() Method in a particular time interval lapses using the Timer control, but before calling the DataBind() method, have you assigned the updated data source for the Gridview ? For eg; When the page loads you are drawing the gridview using a Dataset named "EmployeeDS". so after some update, you need to update the local dataset like below to the gridview, then call the DataBind() method.
GridView1.DataSource = EmployeeDS.Table[0];
GridView1.DataBind();
Related
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.
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.
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 gridview in an updatepanel where also my dropdownlist is. From the Trigger of the dropdownlist I am refreshing my gridview with the slected value. All that is working fine. The problem is that I am also displaying the gridview row count on the page which is also inside the updatepanel. The update seems to be happening to it, one selection too late.
protected void Drop_Change(object sender, EventArgs e)
{
String Value = AjaxDrop.SelectedValue;
GridView1.SelectParameters["Target"].DefaultValue=Value;
RowCount.InnerText = GridView1.Rows.Count.ToString();
}
I think its happening one selection behind because the parameter updates the gridview rowcount too late for the RowCount value to have it, what is a work around to get the actual value after parameter passed. Only way I can think of is using javascript and I wonder if that would even work. My desired solution would be to keep it all on server side though.
At the time you're calling this, the GridView hasn't done it's databinding, therefore the value is not valid. Move your RowCount.InnerText updating to somewhere that gets executed after the DataBinding event (e.g. Page_OnPreRender), or force the DataBinding to occur before you update the row count.
It's worth noting that GridView.Rows.Count isn't a reliable source of information if you are using GridView paging - as this will be the number of rows on one page, even if there are more rows returned by the query.
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