Results 1 to 7 of 7

Thread: Refresh in code?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Refresh in code?

    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

  2. #2
    Addicted Member
    Join Date
    Dec 2002
    Posts
    175
    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?

  3. #3
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    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.
    Magiaus

    If I helped give me some points.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    You could place a <meta> refresh tag in the header.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    To magiaus: Do you apply an autopostback=true in the datagrid or...? How do I apply refresh in <meta>?

  6. #6
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    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 senderSystem.EventArgs e)
            {
                if(
    Business.Contacts.ContactList.GetContactCount(Business.Helpers.Convert.ToContact(((Business.Contacts.Security.LoginResults)Session["-login"]).Contact).KeyBusiness.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).Keytrue10dg_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).KeyBusiness.Contacts.ContactList.ListTypes.Contact);
                
    dg_contacts.SelectedIndex = -1;
                
    dg_contacts.DataSource bcc;
                
    dg_contacts.DataBind();
            }
            private 
    void dg_contacts_PageIndexChanged(object sourceSystem.Web.UI.WebControls.DataGridPageChangedEventArgs e)
            {
                
    dg_contacts.CurrentPageIndex e.NewPageIndex;
                
    BindGrid();
            }
            private 
    void dg_contacts_ItemDataBound(object senderSystem.Web.UI.WebControls.DataGridItemEventArgs e)
            {
                
    //add style tag to hyperlinks
                
    if(e.Item.Controls.Count 0)
                {
                    for(
    int i 0e.Item.Controls.Counti++)
                    {
                        if(
    e.Item.Controls[i].GetType().ToString() == "System.Web.UI.WebControls.TableCell")
                        {
                            if(
    e.Item.Controls.Count 0)
                            {
                                for(
    int j 0e.Item.Controls[i].Controls.Countj++)
                                {
                                    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 senderSystem.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();
                }
            }

        } 
    Magiaus

    If I helped give me some points.

  7. #7
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    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
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width