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

[Solved] NeedDataSource Not Firing

2 Answers 242 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 02 Jun 2008, 12:00 AM
Hello,

I'm attempting to use the advanced databind feature and the NeedDataSource and cant seem to get the event to fire.

I was having trouble getting it to launch in an existing page so I created a new content page (based on a simplistic Master page), dropped a grid on the page, configured a couple columns via the Property Builder, then added the NeedDataSource contruct...

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
        SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);  
        SqlDataAdapter da = new SqlDataAdapter();  
        DataSet ds = new DataSet();  
        MessageBox.Show("Blah");  
 
        try  
        {  
            myConn.Open();  
            da.SelectCommand = new SqlCommand("select *, DateDiff(d,TimeStamp,GetDate()) as DaysOld, DateDiff(m,TimeStamp,GetDate()) as MonthsOld,RANK() OVER (order by TIMESTAMP) as RowNumber from ReadHistory where CardID = 'ABC00002' order by TimeStamp", myConn);  
            da.Fill(ds, "ReadData");  
            DataView dv = ds.Tables["ReadData"].DefaultView;  
            Session["ReadData"] = dv;  
            RadGrid1.DataSource = dv;  
        }  
        catch (Exception ex)  
        {  
            MessageBox.Show("Error Loading Data: " + ex.Message.ToString());  
        }  
        finally  
        {  
            myConn.Close();  
        }  
    } 

...and no data is in the grid.  I know that the select coding works because its a copy of the method I was calling from the Page_Load event to populate the grid before trying the advanced binding option. The message box in the snippet never even fires.  The grid is set to Visible and, in this example, was never bound to any data source.

Any help would be appreciated.

Thanks in advance,
Rick

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Jun 2008, 04:52 AM
Hi Rick,

Have you set the proper EventHandler for the NeedDataSource event?

ASPX:
<telerik:radgrid id="RadGrid1" runat="server"   datasourceid="SqlDataSource1"   
OnNeedDataSource="RadGrid1_NeedDataSource" > 
 

CS:
 protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
    {  
 
    } 


Princy.
0
Rick
Top achievements
Rank 1
answered on 02 Jun 2008, 11:42 PM
That did it.  I mis-interpreted "RadGrid fires the NeedDataSource event each time it needs to be bound to a data source" from the Help file as saying the grid was already wired up to launch the event if it was not already bound to a datasource.

Thanks,
Rick
Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rick
Top achievements
Rank 1
Share this question
or