No records to display. Using DataTable as DataSource of RadGrid

4 posts, 0 answers
  1. liu qingshui
    liu qingshui avatar
    27 posts
    Member since:
    Mar 2010

    Posted 09 Jun 2010 Link to this post

    Urgent Help please,I am using databable as datasource,but RadGrid show "No records to display".
    <
    telerik:RadGrid ID="rgReportList" runat="server"  OnNeedDataSource="rgReportList_NeedDataSource" 
                        AllowSorting="True" AllowPaging="True"   ShowHeader="true" > 
                    </telerik:RadGrid> 

     protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                rdpRequestDateStart.SelectedDate = DateTime.Now.AddMonths(-1); 
                rdpRequestDateEnd.SelectedDate = DateTime.Now; 
                rgReportList.DataSource = CreateDataSource("日期""按天统计", DateTime.Parse(DateTime.Now.Date.AddDays(-7).ToShortDateString()), DateTime.Parse(DateTime.Now.ToShortDateString())); 
                rgReportList.MasterTableView.DataBind(); 
                //rgReportList.MasterTableView.Rebind(); 
                //rgReportList.MasterTableView.HierarchyDefaultExpanded = true; 
                rgReportList.DataBind(); 
     
            } 
        } 



    protected
     void rgReportList_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
        { 
            rgReportList.DataSource = CreateDataSource("日期", ddltype.Value, (DateTime)rdpRequestDateStart.SelectedDate, (DateTime)rdpRequestDateEnd.SelectedDate); 
        } 
      private DataTable CreateDataSource(String categroy, String statisticType, DateTime startDay, DateTime endDay) 
        { 
            //DataSet dataset = new DataSet(); 
            DataTable dataTable = new DataTable(); 
            dataTable.TableName = "ReportByDate"
            dataTable.Columns.Add("时间"); 
            dataTable.Columns.Add("完成事件数"); 
            dataTable.Columns.Add("工时"); 
            dataTable.Columns.Add("处理中事件"); 
     
            //dataset.Tables.Add(dataTable); 
            for (DateTime dt =startDay; dt <= endDay; dt=dt.AddDays(1)) 
            { 
                UserRequestInfoCollection urList = UserRequest.List("", dt, dt.AddDays(1)); 
                Int32 totalThingsByEachDate = 0; 
                Int32 tsTotalWorkHours = 0; 
                Int32 totalNotFinishedThings = 0; 
                if (urList.Count!=0) 
                { 
                    foreach (UserRequestInfo uri in urList) 
                    { 
                        totalThingsByEachDate++; 
                        //tsTotalWorkHours+= ((TimeSpan)(uri.ExpectTime - uri.RequestTime)).Hours; 
                        if (!(Boolean)uri.IsClose) 
                        { 
                            totalNotFinishedThings++; 
                        } 
                     
                    } 
               
                 
                } 
                dataTable.Rows.Add(new String[] { dt.ToString(), totalThingsByEachDate.ToString(), tsTotalWorkHours.ToString(), totalNotFinishedThings.ToString() }); 
     
            } 
     
            return dataTable; 
        } 

  2. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 15 Jun 2010 Link to this post

    Hello Liu Qingshui,

    First of all, you should not use simple databinding (in Page_Load) and advanced databinding (with NeedDataSource) at the same time.

    Otherwise I don't see anything wrong and the RadGrid gets populated. Here is my test page:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <script runat="server">
     
        protected void rgReportList_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            rgReportList.DataSource = CreateDataSource("日期", "ddltype.Value", DateTime.Now.AddDays(-10), DateTime.Now);
        }
         
        private DataTable CreateDataSource(String categroy, String statisticType, DateTime startDay, DateTime endDay)
        {
            //DataSet dataset = new DataSet();
            DataTable dataTable = new DataTable();
            dataTable.TableName = "ReportByDate";
            dataTable.Columns.Add("时间");
            dataTable.Columns.Add("完成事件数");
            dataTable.Columns.Add("工时");
            dataTable.Columns.Add("处理中事件");
     
            //dataset.Tables.Add(dataTable);
            for (DateTime dt = startDay; dt <= endDay; dt = dt.AddDays(1))
            {
                dataTable.Rows.Add(new String[] { dt.ToString(), "1", "1", "1" });
     
            }
     
            return dataTable;
        }
         
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     
    <head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>RadControls</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
     
    <telerik:RadGrid ID="rgReportList" runat="server"  OnNeedDataSource="rgReportList_NeedDataSource"
        AllowSorting="True" AllowPaging="True"   ShowHeader="true" >
    </telerik:RadGrid>
                     
    </form>
    </body>
    </html>


    Best wishes,
    Dimo
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Viren
    Viren avatar
    4 posts
    Member since:
    Aug 2010

    Posted 19 Oct 2010 Link to this post

    Hi,

    I am trying to do something similar. I am using an image gallery control on one of my templates inside sitefinity. The template is just a .master file without a code behind. So I added a code behind file manually to main template.master file and wrote a CreateDataSource method that opens a connection to my database. Then as guided by the Telerik team, I am calling a class under App_Code that returns images from my database as IContent objects from within this overridden CreateDataSource method.

    However when I try to build the sitefinity project in visual studio I get the following error:

    Error   119   'App_Master_templateName.CreateDataSource(object, System.EventArgs)': no suitable method found to override   C:\Program Files (x86)\Telerik\Sitefinity3.7\WebSites\projectName\App_Master\templateName.master.cs   30   30   C:\...\projectName\

    Can you please guide me as to where to write the method CreateDataSource to override the base class method? I do not have code behind file for the template of the image gallery control as it is an embedded control. How do I point the image gallery control to this new CreateDataSource method? I am assuming that I can continue using the generic image gallery control and just override the CreateDataSource method. If not then do I have to inherit a new image gallery control? What are the config settings needed for that?

    Thanks

    Thanks
     
  5. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 20 Oct 2010 Link to this post

    Hi Viren,

    Please do not post duplicate forum posts on the same topic. Your inquiry will be addressed at:

    http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/setting-up-external-db-within-web-config-file.aspx

    Greetings,
    Dimo
    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
Back to Top