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

No records to display. Using DataTable as DataSource of RadGrid

3 Answers 301 Views
Grid
This is a migrated thread and some comments may be shown as answers.
liu qingshui
Top achievements
Rank 1
liu qingshui asked on 10 Jun 2010, 04:09 AM
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; 
    } 

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 15 Jun 2010, 07:46 AM
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.
0
Viren
Top achievements
Rank 1
answered on 20 Oct 2010, 04:02 AM
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
 
0
Dimo
Telerik team
answered on 20 Oct 2010, 06:46 AM
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
Tags
Grid
Asked by
liu qingshui
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Viren
Top achievements
Rank 1
Share this question
or