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

Unable to Filter Grid when setting DataSource in Code behind

1 Answer 56 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Civbaron asked on 09 Apr 2010, 04:01 PM

I was trying to get the example of simple filtering working that is located at this location I was able to get it working without too much trouble. The issue is that when I removed the 'DataSourceID="SqlDataSource1' from the Grid and used code in the Page_Load method to set the Datasource of the grid the filtering did not work. I set the datasource to be a list of ints. I have also tried using the NeedDataSource event of the grid itself to populate the grid, but again the grid will be populated but when I go to filter it doesn't filter.  Here is sample of the code I am using to set the datasource of the grid:

SqlCommand sql =

new SqlCommand();


SqlDataAdapter da =

new SqlDataAdapter();



string connectionString = WebConfigurationManager.ConnectionStrings["SBF"].ToString();


SqlConnection con =

new SqlConnection(connectionString);





con.ConnectionString = connectionString;

sql.CommandText =

@"select A from SSA";


sql.Connection = con;

da.SelectCommand = sql;

DataTable dt =

new DataTable();



List<int> ints = new List<int>();




for (int i = 0; i < dt.Rows.Count; i++)








RadGrid1.DataSource = ints;

I am using the 2009.3.1208.35 version of the Telerik.Web.UI.

Jonathan Simon

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 15 Apr 2010, 07:40 AM
Hi Jonathan,

In order to make sure that the control's functionalities are executed as expected, it is necessary to bind the control by using NeedDataSource:

or a datasource control:

Setting the datasource in any other event, or calling .DataBind() for the control directly would not allow it to function as expected.
I hope this information helps.

Sincerely yours,
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question