I have an app including af DataGrid. Can I refresh the page with some code instead of clicking the "Refresh" -icon in the browser? The DataGrid is reading from a database and hence that there is a small delay, so I have to refresh
Printable View
I have an app including af DataGrid. Can I refresh the page with some code instead of clicking the "Refresh" -icon in the browser? The DataGrid is reading from a database and hence that there is a small delay, so I have to refresh
Surely the datagrid is refreshed in you apps post back after the DB has been read and DS filled?
I don't understand - can you explain please?
you could use javascript and set a timer to refresh (window.refrsh();...?)
you could add a link column and have it text: Refresh url: javascript:window.refresh();
or maybe you need to call DataBind in the page_load. I call it on every post back I have a method BindGrid() that does all the binding for a grid.
You could place a <meta> refresh tag in the header.
To magiaus: Do you apply an autopostback=true in the datagrid or...? How do I apply refresh in <meta>?
Mendhak does that <meta> tag still work I haven't used it since like 1998...
this is a user control. I put my grids in UserControls so I can reuse them.
PHP Code:public abstract class Pager : System.Web.UI.UserControl
{
private void Page_Load(object sender, System.EventArgs e)
{
if(Business.Contacts.ContactList.GetContactCount(Business.Helpers.Convert.ToContact(((Business.Contacts.Security.LoginResults)Session["-login"]).Contact).Key, Business.Contacts.ContactList.ListTypes.Contact) == 0)
{
pnl_grid.Visible = false;
pnl_noData.Visible = true;
}
else
{
pnl_grid.Visible = true;
pnl_noData.Visible = false;
BindGrid();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dg_contacts.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_contacts_ItemCreated);
this.dg_contacts.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dg_contacts_PageIndexChanged);
this.dg_contacts.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_contacts_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
protected System.Web.UI.WebControls.DataGrid dg_contacts;
protected System.Web.UI.WebControls.Panel pnl_noData;
protected System.Web.UI.WebControls.Panel pnl_grid;
Business.Contacts.ContactCollection bcc;
private void BindGrid()
{
bcc = new Business.Contacts.ContactCollection(Business.Helpers.Convert.ToContact(((Business.Contacts.Security.LoginResults)Session["-login"]).Contact).Key, true, 10, dg_contacts.CurrentPageIndex);
//change this as soon as you write a count to match this and wrap it
rowCount = dg_contacts.CurrentPageIndex * 10;
dg_contacts.VirtualItemCount = Business.Contacts.ContactList.GetContactCount(Business.Helpers.Convert.ToContact(((Business.Contacts.Security.LoginResults)Session["-login"]).Contact).Key, Business.Contacts.ContactList.ListTypes.Contact);
dg_contacts.SelectedIndex = -1;
dg_contacts.DataSource = bcc;
dg_contacts.DataBind();
}
private void dg_contacts_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dg_contacts.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
private void dg_contacts_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//add style tag to hyperlinks
if(e.Item.Controls.Count > 0)
{
for(int i = 0; i < e.Item.Controls.Count; i++)
{
if(e.Item.Controls[i].GetType().ToString() == "System.Web.UI.WebControls.TableCell")
{
if(e.Item.Controls.Count > 0)
{
for(int j = 0; j < e.Item.Controls[i].Controls.Count; j++)
{
if(e.Item.Controls[i].Controls[j].GetType().ToString() == "System.Web.UI.WebControls.HyperLink")
{
((System.Web.UI.WebControls.HyperLink)e.Item.Controls[i].Controls[j]).CssClass = "pkGridLink";
((System.Web.UI.WebControls.HyperLink)e.Item.Controls[i].Controls[j]).Attributes.Add("onmouseover", "status='PK Promotions ~ Custom Importing and Exporting.';return true;");
}
}
}
}
}
}
}
int rowCount = 0;
private void dg_contacts_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == System.Web.UI.WebControls.ListItemType.AlternatingItem || e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item || e.Item.ItemType == System.Web.UI.WebControls.ListItemType.EditItem || e.Item.ItemType == System.Web.UI.WebControls.ListItemType.SelectedItem)
{
rowCount++;
e.Item.Cells[0].Text = rowCount.ToString();
}
}
}
If you look at the page load you'll see that if they have contacts I call Bind grid on every page load.
I know the C# code is nasty looking but I quit VB. That <meta name=refresh> I just straight don't remember 1998 was along time ago