This is a migrated thread and some comments may be shown as answers.

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

3 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Waleed Seada
Top achievements
Rank 2
Waleed Seada asked on 27 May 2008, 01:01 PM
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

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 May 2008, 04:47 AM

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.

0
Waleed Seada
Top achievements
Rank 2
answered on 28 May 2008, 05:40 AM
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
0
Waleed Seada
Top achievements
Rank 2
answered on 29 May 2008, 09:54 AM

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
Tags
Grid
Asked by
Waleed Seada
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Waleed Seada
Top achievements
Rank 2
Share this question
or