Multi Grids Inside PanelBar Performance ... How To !!

4 posts, 0 answers
  1. Waleed Seada
    Waleed Seada avatar
    241 posts
    Member since:
    May 2006

    Posted 27 May 2008 Link to this post

    Dear all,

    I have a RadPanelBar with 10 RadGrid inside it's template items.

    Each one of these Grids might have up to 10,000 record each.
    For sack of performance I decided to make the grids fill with data only on the Panel Item click and in order to keep up the performance I unload the previously loaded grid.

    The Issues is that when you click again on the panelbar non of the grids show any rows at all.

    Here is my approach:
    I place each grid in one of the item template inside the panelbar.

    I attached EventHandler to their OnNeedDataSource where I load the data.
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
            {  
                LoadData(Grid1);  
            } 

    I create a method to unload the data from all the grids before filling any of them.

    private void UnloadDataFromAll()  
    {  
        Grid1.DataSource = GetDataTable("");  
        Grid1.DataBind();  
        Grid2.DataSource = GetDataTable("");  
        Grid2.DataBind();  

    and the GetDataTable.
    public DataTable GetDataTable(string query)  
            {  
                if (query == "")  
                {  
                    return new DataTable("");  
                }  
                String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;  
                SqlConnection conn = new SqlConnection(ConnString);  
                SqlDataAdapter adapter = new SqlDataAdapter();  
                adapter.SelectCommand = new SqlCommand(query, conn);  
     
                DataTable myDataTable = new DataTable();  
     
                conn.Open();  
                try 
                {  
                    adapter.Fill(myDataTable);  
                }  
                finally 
                {  
                    conn.Close();  
                }  
     
                return myDataTable;  
            } 

    What do I missing here ...
    Greetings,
    Waleed
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 May 2008 Link to this post

    Hi,

    You should never call the DataBind() method from inside the NeedDataSource handler or mix simple data-binding mode with advanced data-binding. Go through the following demo link to get more information about AdvanceDataBinding techniques.
    Advanced data-binding

    Princy.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Waleed Seada
    Waleed Seada avatar
    241 posts
    Member since:
    May 2006

    Posted 28 May 2008 Link to this post

    Hello Princy,

    I guess you mean this line in the unloaddatafromall(), although it is not in the needdatasource as you said but thanks for your input.

    How about the implementation approach, any inputs ....

    Best,
    Waleed
  5. Waleed Seada
    Waleed Seada avatar
    241 posts
    Member since:
    May 2006

    Posted 29 May 2008 Link to this post

    Dear all,

    I changed a little the way I manipulate the RadGrids inside the RadPanel object, in the way to achieve what I want, and I am going ahead forward.

    Except that I am facing a small difficulty:
    I load one grid with the data and when I try to click on Next page I loss the Grid with the data in it. !!

    What can I do to avoid this..

    Here is the C# code I have:

        private void LoadData(RadGrid gridObj)  
            {  
                switch (gridObj.ID)  
                {  
                    case "RadGrid1":  
                        gridObj.DataSource = GetDataTable("SELECT EmployeeID, LastName, FirstName, Title, HireDate, Address FROM Employees");   
                        //gridObj.DataBind();  
                        break;  
                    case "RadGrid2":  
                        gridObj.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers");  
                        //gridObj.DataBind();  
                        break;  
                    default:  
                        gridObj.DataSource = new DataTable();  
                        //gridObj.DataBind();  
                        return;  
                }  
            }  
     
            private void UnloadDataFromAll()  
            {  
                Grid1.DataSource = GetDataTable("");  
                Grid2.DataSource = GetDataTable("");  
            }  
     
            public DataTable GetDataTable(string query)  
            {  
                if (query == "")  
                {  
                    return new DataTable("");  
                }  
                String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;  
                SqlConnection conn = new SqlConnection(ConnString);  
                SqlDataAdapter adapter = new SqlDataAdapter();  
                adapter.SelectCommand = new SqlCommand(query, conn);  
     
                DataTable myDataTable = new DataTable();  
     
                conn.Open();  
                try 
                {  
                    adapter.Fill(myDataTable);  
                }  
                finally 
                {  
                    conn.Close();  
                }  
     
                return myDataTable;  
            }  
     
            protected void NewsPanel_ItemClick(object sender, RadPanelBarEventArgs e)  
            {  
               switch(e.Item.Value)  
               {  
                    case "PanelItem1":  
                        UnloadDataFromAll();  
                        LoadData(Grid1);  
                        Grid1.DataBind();  
                        break;  
                    case "PanelItem2":  
                        UnloadDataFromAll();  
                        LoadData(Grid2);  
                        Grid2.DataBind();  
                        break;  
                    default:  
                        return;  
               }  
            } 
    Thanks and best regards,
    Waleed
Back to Top