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

Two Radgrids: Losing one on sort, filter, page, etc.

4 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Craig Smith
Top achievements
Rank 1
Craig Smith asked on 23 Apr 2008, 06:58 PM
As soon as I try to filter, page, sort, group one of the grids all of its information disappears. Here is the code...

namespace HeaderInfoViewer  
{  
    public partial class _Default : System.Web.UI.Page  
    {  
          
        protected void btnSubmit_Click(object sender, EventArgs e)  
        {  
            SqlDataSource1.SelectCommand = "select Barcode,Description SamplePointName, UWI, updated_dt DateUpdated, well_license WellLicense, well_name WellName, Field, Pool, Formation, Matrix from ana_sample_points where UWI like '%" + rtxtUWI.Text + "%'";  
            SqlDataSource2.SelectCommand = "select UWI, well_name Wellname, Fieldname, Poolname, well_license WellLicense from eub_well,eub_field, eub_pool_field " +  
                " where eub_well.fieldcode = eub_field.fieldcode" +  
                " and eub_well.poolcode = eub_pool_field.poolcode" +  
                " and uwi like '%" + rtxtUWI.Text + "%'";  
 
            rgInternal.Rebind();  
            rgEUB.Rebind();  
        }  
 
        protected void rgInternal_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            rgInternal.DataSource = SqlDataSource1;  
        }  
 
        protected void rgEUB_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            rgEUB.DataSource = SqlDataSource2;  
        }  
    }  


4 Answers, 1 is accepted

Sort by
0
Craig Smith
Top achievements
Rank 1
answered on 23 Apr 2008, 09:00 PM
Update: It doesn't matter that there are two radgrids. Even with one the data disappears when I try to sort, etc.
0
Craig Smith
Top achievements
Rank 1
answered on 23 Apr 2008, 11:21 PM
I've wasted an entire day trying to understand why I can't filter or sort or page when I set the selectcommand of the sqldatasource dynamically. It all works great if I set the selectcommand at design time. I don't understand why it makes a difference.
0
Craig Smith
Top achievements
Rank 1
answered on 24 Apr 2008, 02:59 AM
I'm having a conversation with myself here but that's okay. I have mostly figured it out. I needed to set the datasource to null before calling rebind. Now the sorting and the grouping are working but the filtering and the paging still don't work. Here is my latest code...

    
public partial class _Default : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (IsPostBack)  
            {  
                setDataSources();  
                rgInternal.Rebind();  
                rgEUB.Rebind();  
            }  
        }  
        protected void btnSubmit_Click(object sender, EventArgs e)  
        {  
            setDataSources();  
            rgInternal.DataSource = null;  
            rgEUB.DataSource = null;  
              
        }  
 
        protected void setDataSources()  
        {  
            SqlDataSource1.SelectCommand = "select Barcode,Description SamplePointName, UWI, updated_dt DateUpdated, well_license WellLicense, well_name WellName, Field, Pool, Formation, Matrix from ana_sample_points where UWI like '%" + rtxtUWI.Text + "%'";  
            SqlDataSource2.SelectCommand = "select UWI, well_name Wellname, Fieldname, well_license WellLicense from eub_well,eub_field " +  
                " where eub_well.fieldcode = eub_field.fieldcode" +  
                " and uwi like '%" + rtxtUWI.Text + "%'";  
 
            //rgInternal.DataSource = SqlDataSource1;  
            //rgEUB.DataSource = SqlDataSource2;  
            //rgInternal.DataBind();  
            //rgEUB.DataBind();  
        }  
 
          
        protected void rgInternal_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            rgInternal.DataSource = SqlDataSource1;  
        }  
 
        protected void rgEUB_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            rgEUB.DataSource = SqlDataSource2;  
        }  
    } 
0
Accepted
Vlad
Telerik team
answered on 24 Apr 2008, 06:31 AM
Hello Craig,

When using DataSourceControls please bind the grid declaratively using DataSourceID not directly assigning the DataSourceControl to grid DataSource.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Craig Smith
Top achievements
Rank 1
Answers by
Craig Smith
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or