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

Grid won't show my data

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nikola
Top achievements
Rank 2
Nikola asked on 15 Nov 2012, 01:53 PM
Heeey guys 

i have a quest what do i do wrong that there is no data to be displayed ? 


<%@ Page Title="" Language="C#" MasterPageFile="~/ABBMaster.Master" AutoEventWireup="true" CodeBehind="YearMonthReport.aspx.cs" Inherits="HolidayTracker.Testing.YearMonthReaport" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="MainRegionContentPlaceHolder" runat="server">
    <link rel="Stylesheet" type="text/css" href="ReportStyle.css" />
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1"></telerik:RadScriptManager>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function onRequestStart(sender, args) {
                if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
                 args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
                 args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
                    args.set_enableAjax(false);
                }
            }
            function getOuterHTML(obj) {
                if (typeof (obj.outerHTML) == "undefined") {
                    var divWrapper = document.createElement("div");
                    var copyOb = obj.cloneNode(true);
                    divWrapper.appendChild(copyOb);
                    return divWrapper.innerHTML
                }
                else
                    return obj.outerHTML;
            }
 
 
 
 
            function PrintRadGrid() {
                {
                    var previewWnd = window.open('about:blank', '', '', false);
                    var sh = '<%= ClientScript.GetWebResourceUrl(UserGrid.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",UserGrid.Skin)) %>';
                    var shBase = '<%= ClientScript.GetWebResourceUrl(UserGrid.GetType(),"Telerik.Web.UI.Skins.Grid.css") %>';
                    var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link>";
                    styleStr += "<link href = '" + shBase + "' rel='stylesheet' type='text/css'></link></head>";
                    var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= UserGrid.ClientID %>').get_element()) + "</body></html>";
                    previewWnd.document.open();
                    previewWnd.document.write(htmlcontent);
                    previewWnd.document.close();
                    previewWnd.print();
 
                    if (!$telerik.isChrome) {
                        previewWnd.close();
                    }
                }
            }
 
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <ClientEvents OnRequestStart="onRequestStart" />
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="UserGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="UserGrid" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxPanel runat="server" Height="600px" ID="RadAjaxPanel1">
        <div class="qsf-demo-canvas">
            <div class="Year" runat="server">
                <telerik:RadComboBox ID="rcbYear" runat="server" Visible="false" Width="186px" Label="Year: " AutoPostBack="true" OnSelectedIndexChanged="rcbYear_SelectedIndexChanged">
                </telerik:RadComboBox>
            </div>
            <div class="Month">
                <telerik:RadComboBox ID="rcbMonth" runat="server" Visible="false" Width="186px" Label="Month: " AutoPostBack="true" OnSelectedIndexChanged="rcbMonth_SelectedIndexChanged">
                </telerik:RadComboBox>
            </div>
            <p class="button">
                <asp:Button ID="Button1" runat="server" Text="Show Report Year/Month" OnClick="Button1_Click" />
            </p>
            <div>
                <p>
                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Administrator/printer-icon.png" Visible="false" OnClick="ImageButton1_Click" />
                </p>
            </div>
            <div class="UserGrid">
                <telerik:RadGrid ID="UserGrid" runat="server" Visible="false" CellSpacing="0" GridLines="None" AllowPaging="true" PageSize="10" OnItemCommand="UserGrid_ItemCommand" Height="400">
                   <AlternatingItemStyle BackColor="Green" />
                     <ExportSettings HideStructureColumns="true">
                    </ExportSettings>
                    <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false"+>
                        <CommandItemSettings ShowAddNewRecordButton="false" />
                        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                        <CommandItemSettings ShowExportToExcelButton="true" ShowExportToCsvButton="false" ShowExportToWordButton="false" />
                        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>
 
                        <Columns>
                            <telerik:GridBoundColumn DataField="FirstName" FilterControlAltText="Filter FirstName column" HeaderText="First Name" SortExpression="FirstName" UniqueName="FirstName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="LastName" FilterControlAltText="Filter LastName column" HeaderText="Last Name" SortExpression="LastName" UniqueName="LastName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="1" HeaderText="1" UniqueName="1"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="2" HeaderText="2" UniqueName="2"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="3" HeaderText="3" UniqueName="3"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="4" HeaderText="4" UniqueName="4"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="5" HeaderText="5" UniqueName="5"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="6" HeaderText="6" UniqueName="6"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="7" HeaderText="7" UniqueName="7"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="8" HeaderText="8" UniqueName="8"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="9" HeaderText="9" UniqueName="9"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="10" HeaderText="10" UniqueName="10"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="11" HeaderText="11" UniqueName="11"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="12" HeaderText="12" UniqueName="12"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="13" HeaderText="13" UniqueName="13"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="14" HeaderText="14" UniqueName="14"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="15" HeaderText="15" UniqueName="15"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="16" HeaderText="16" UniqueName="16"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="17" HeaderText="17" UniqueName="17"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="18" HeaderText="18" UniqueName="18"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="19" HeaderText="19" UniqueName="19"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="20" HeaderText="20" UniqueName="20"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="21" HeaderText="21" UniqueName="21"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="22" HeaderText="22" UniqueName="22"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="23" HeaderText="23" UniqueName="23"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="24" HeaderText="24" UniqueName="24"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="25" HeaderText="25" UniqueName="25"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="26" HeaderText="26" UniqueName="26"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="27" HeaderText="27" UniqueName="27"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="28" HeaderText="28" UniqueName="28"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="29" HeaderText="29" UniqueName="29"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="30" HeaderText="30" UniqueName="30"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="31" HeaderText="31" UniqueName="31"></telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
 
                </telerik:RadGrid>
            </div>
    </telerik:RadAjaxPanel>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
</asp:Content>

code behind 

using HolidayTracker.Code;
using HolidayTracker.Data.Model;
using HolidayTracker.Report;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using eis = Telerik.Web.UI.ExportInfrastructure;
 
namespace HolidayTracker.Testing
{
    public partial class YearMonthReaport : System.Web.UI.Page
    {
        private HtUser user;
        private HtUser User
        {
            get
            {
                user = HtUser.INIT_USER(this.Page, true);
                return user;
            }
        }
 
        #region Views
        private HtVacationDay selectYear
        {
            get
            {
                return (HtVacationDay)ViewState["selectYear"];
            }
            set
            {
                ViewState["selectYear"] = value;
            }
 
        }
        private  HtVacationDay selectMonth
        {
            get
            {
                return (HtVacationDay)ViewState["selectMonth"];
            }
            set
            {
                ViewState["selectMonth"] = value;
            }
 
        }
 
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadYear();
                LoadMonth();
            }
            if (User.HtUserRoles.Where(u => u.Name == UserRoles.LbuLeader.ToString()).Any())
            {
                this.rcbYear.Visible = true;
                this.rcbMonth.Visible = true;
            }
            if (User.HtUserRoles.Where(u => u.Name == UserRoles.Administrator.ToString()).Any())
            {
                this.rcbMonth.Visible = true;
                this.rcbYear.Visible = true;
            }
            else if (User.HtUserRoles.Where(u => u.Name == UserRoles.BuLeader.ToString()).Any())
            {
                this.rcbMonth.Visible = true;
                this.rcbYear.Visible = true;
 
            }
            else if (User.HtUserRoles.Where(u => u.Name == UserRoles.DepartmentLeader.ToString()).Any())
            {
                this.rcbMonth.Visible = true;
                this.rcbYear.Visible = true;
            }
            else if (User.HtUserRoles.Where(u => u.Name == UserRoles.BackOffice.ToString()).Any())
            {
                this.rcbYear.Visible = true;
                this.rcbMonth.Visible = true;
            }
 
        }
   
        protected void LoadYear()
        {
           rcbYear.DataSource = HtVacationDay.GetAllVacationYears();
            rcbYear.DataBind();
            rcbYear.Items.Insert(0, new RadComboBoxItem("-Select a Year-"));
 
        }
 
        protected void LoadMonth()
        {
            rcbMonth.DataSource = HtVacationDay.GetAllVacationMonths();
            rcbMonth.DataBind();
            rcbMonth.Items.Insert(0,new RadComboBoxItem("-Select a Month-"));
        }
 
        protected void UserGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||
                 e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName ||
                 e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName)
            {
 
            }
            if (e.CommandName == "EnablePaging")
            {
                UserGrid.AllowPaging = true;
                UserGrid.Rebind();
            }
        }
     
        protected void Button1_Click(object sender, EventArgs e)
        {
            UserGrid.Visible = true;
            ImageButton1.Visible = true;
        }
         protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
 
            foreach (GridItem item in UserGrid.MasterTableView.GetItems(new GridItemType[] { GridItemType.Pager, GridItemType.FilteringItem }))
                item.Display = false;
 
            RadAjaxPanel1.ResponseScripts.Add("PrintRadGrid('" + UserGrid.ClientID + "')");
        }
 
 
        protected override PageStatePersister PageStatePersister
        {
            get
            { return new SessionPageStatePersister(this);}
        }
 
        protected void rcbYear_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            this.selectYear =HtVacationDay.GetById(int.Parse(e.Value));
            dataSourceFilterChanged();
        }
 
        protected void rcbMonth_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            this.selectMonth =HtVacationDay.GetById(int.Parse(e.Value));
            dataSourceFilterChanged();
        }
        private void dataSourceFilterChanged()
        {
            IEnumerable<MonthReportRowItem> reportRowItems = null;
            if (this.selectYear != null)
            {
                if (this.selectMonth != null)
                {
                    
                }
            }
            this.UserGrid.DataSource = reportRowItems;
            this.UserGrid.DataBind();
        }
         
    
 

using HolidayTracker.Data.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace HolidayTracker.Report
{
    public class MonthReportRowItem
    {
 
        public MonthReportRowItem(HtUser user)
        {
            this.user = user;
        }
 
        public MonthReportRowItem(HtUser user, int reportYear)
        {
            this.user = user;
            this.reportYear = reportYear;
            this.monthReport = user.GetMonthReport(reportYear);
        }
 
        #region properties
        private HtVacationDay vacationday;
        private HtUser user;
        private int reportYear;
        private int[] monthReport;
 
        public string FirstName{
            get{
                return this.user.FirstName;
                
            }
        }
        public string LastName{
            get{
                return this.user.LastName;
            }
        }
        public int VacationDays{
            get{
               return this.user.GetAnnualVacationAmountByYear(this.reportYear);
            }
        }
        public int UsedVacationDays{
            get{
                return this.user.GetUsedVacation(this.reportYear);
            }
        }
        public int BookedVacationDays{
            get{
                return user.GetBookedVacation(this.reportYear);
            }
        }
        public int ForecastVacationDays{
            get{
                return (this.BookedVacationDays - this.UsedVacationDays);
            }
        }
 
        public int January{
            get{
                return this.monthReport[1];
            }
        }
        public int February{
            get{
                return this.monthReport[2];
            }
        }
        public int March{
            get{
                return this.monthReport[3];
            }
        }
        public int April{
            get{
                return this.monthReport[4];
            }
        }
        public int May{
            get{
                return this.monthReport[5];
            }
        }
        public int June{
            get{
                return this.monthReport[6];
            }
        }
        public int July{
            get{
                return this.monthReport[7];
            }
        }
        public int August{
            get{
                return this.monthReport[8];
            }
        }
        public int September{
            get{
                return this.monthReport[9];
            }
        }
        public int October{
            get{
                return this.monthReport[10];
            }
        }
        public int November{
            get{
                return this.monthReport[11];
            }
        }
        public int December{
            get{
                return this.monthReport[12];
            }
        }
 
        #endregion
    }
}


thanks for answer 

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 20 Nov 2012, 09:08 AM
Hi,

I reviewed your code and was not able to find where you are filling the datasource of RadGrid. Additionally, I saw that you use datafields like "1", "2",and so on, but in the datasource there was no such fields. In order for RadGrid to display the intended data it should be assigned datasource which is filled with the data and the datafields in the datasource corresponds to the datafields defined in RadGrid.

You could check this online demo application for an example how to bind RadGrid programmatically to different datasources.

Greetings,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Nikola
Top achievements
Rank 2
Answers by
Andrey
Telerik team
Share this question
or