radgrid延迟加载单列

时间:2015-04-15 11:36:29

标签: c# asp.net .net ajax telerik

我有一个带有两个不同数据库的Telerik Radgrid,第一个数据源加载大部分信息,而第二个数据库加载一个列。 我的问题是第一个数据加载速度快,而第二个数据(单个列)速度慢,所以我试图找出一种方法来延迟加载第二个数据源而不必等待整个数据受约束 到目前为止我的代码是

ASPX:

    <telerik:RadGrid ID="rgPointage" runat="server" CellSpacing="0" GridLines="None" AutoGenerateColumns="False" AllowSorting="True" OnItemDataBound="rgPointage_ItemDataBound">


    <MasterTableView DataKeyNames="Matricule">
        <Columns>
            <telerik:GridBoundColumn FilterControlAltText="Filter Matricule column" DataField="Matricule" HeaderText="Matricule" UniqueName="Matricule">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Direction" FilterControlAltText="Filter Direction column" HeaderText="Direction" UniqueName="Direction" AutoPostBackOnFilter="True" FilterControlWidth="80px">
                <ColumnValidationSettings>
                    <ModelErrorMessage Text="" />
                </ColumnValidationSettings>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Nom column" DataField="Nom" HeaderText="Nom" UniqueName="Nom">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Prenom column" DataField="Prenom" HeaderText="Prenom" UniqueName="Prenom">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Etat column" DataField="motif" HeaderText="Etat" UniqueName="Etat">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Pnt1 column" HeaderText="Pointage 1" UniqueName="Pnt1" DataField="Pnt1" DataFormatString="{0:HH:mm}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn Display="false" FilterControlAltText="Filter src1 column" HeaderText="Source 1" UniqueName="src1" DataField="PntSource1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Pnt2 column" HeaderText="Pointage 2" UniqueName="Pnt2" DataField="Pnt2" DataFormatString="{0:HH:mm}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn Display="false" FilterControlAltText="Filter src2 column" HeaderText="Source 2" UniqueName="src2" DataField="PntSource2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Pnt3 column" HeaderText="Pointage 3" UniqueName="Pnt3" DataField="Pnt3" DataFormatString="{0:HH:mm}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn Display="false" FilterControlAltText="Filter src3 column" HeaderText="Source 3" UniqueName="src3" DataField="PntSource3">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Pnt4 column" HeaderText="Pointage 4" UniqueName="Pnt4" DataField="Pnt4" DataFormatString="{0:HH:mm}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn Display="false" FilterControlAltText="Filter src4 column" HeaderText="Source 4" UniqueName="src4" DataField="PntSource4">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Pnt5 column" HeaderText="Pointage 5" UniqueName="Pnt5" DataField="Pnt5" DataFormatString="{0:HH:mm}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn Display="false" FilterControlAltText="Filter src5 column" HeaderText="Source 5" UniqueName="src5" DataField="PntSource5">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter Pnt6 column" HeaderText="Pointage 6" UniqueName="Pnt6" DataField="Pnt6" DataFormatString="{0:HH:mm}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn Display="false" FilterControlAltText="Filter src6 column" HeaderText="Source 6" UniqueName="src6" DataField="PntSource6">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:

protected void getPointage(DateTime date)
        {
            try
            {
                DataTable dt = new DataTable();
                if (!SP)
                    dt = getChildren(getFather());
                else
                    dt = getAll();

                if (dt == null)
                    return;
                listePointage.Clear();
                foreach (DataRow emp in dt.Rows)
                {

                    using (var DB = new PRHEntities())
                    {
                        string matr = emp["Matricule"].ToString();
                        string nomEmp = emp["NomEmploye"].ToString();
                        string prenomEmp = emp["PrenomEmploye"].ToString();
                        string direction = emp["Direction"].ToString();
                        PointagePersonne pointage = (from p in DB.Fn_PointageParJour(matr, date)
                                                     select new PointagePersonne
                                                     {
                                                         Matricule = matr,
                                                         Nom = nomEmp,
                                                         Prenom = prenomEmp,
                                                         Direction = direction,
                                                         Pnt1 = p.Pnt1,
                                                         Pnt2 = p.Pnt2,
                                                         Pnt3 = p.Pnt3,
                                                         Pnt4 = p.Pnt4,
                                                         Pnt5 = p.Pnt5,
                                                         Pnt6 = p.Pnt6,
                                                         PntSource1 = p.PntID1,
                                                         PntSource2 = p.PntID2,
                                                         PntSource3 = p.PntID3,
                                                         PntSource4 = p.PntID4,
                                                         PntSource5 = p.PntID5,
                                                         PntSource6 = p.PntID6
                                                     }).FirstOrDefault<PointagePersonne>();

                        if (!object.Equals(pointage, null))
                        {
                            pointage.PntSource1 = getSourcePointage(pointage.PntSource1);
                            pointage.PntSource2 = getSourcePointage(pointage.PntSource2);
                            pointage.PntSource3 = getSourcePointage(pointage.PntSource3);
                            pointage.PntSource4 = getSourcePointage(pointage.PntSource4);
                            pointage.PntSource5 = getSourcePointage(pointage.PntSource5);
                            pointage.PntSource6 = getSourcePointage(pointage.PntSource6);
                            pointage.motif = getmotifAbsence(matr, date);
                            listePointage.Add(pointage);
                        }
                        else
                        {
                            var nonPnt = new PointagePersonne()
                            {
                                Matricule = matr,
                                Nom = nomEmp,
                                Prenom = prenomEmp,
                                Direction = direction,
                                Pnt1 = null,
                                Pnt2 = null,
                                Pnt3 = null,
                                Pnt4 = null,
                                Pnt5 = null,
                                Pnt6 = null,
                                motif = getmotifAbsence(matr, date)
                            };
                            listePointage.Add(nonPnt);
                        }
                    }
                }

                rgPointage.DataSource = listePointage;
                rgPointage.DataBind();


                ViewState["pointage"] = listePointage;
                if (rgPointage.Items.Count > 1)
                {
                    btExportPointage.Visible = true;
                }
                else
                    btExportPointage.Visible = false;

            }
            catch (Exception ex)
            {
//
            }


        }

所以我试图做的是在加载和显示radgrid之后为每一行加载方法getmotifAbsence(matr,date)。

1 个答案:

答案 0 :(得分:0)

我认为你不能。服务器代码是同步的,因此它一次一行,所以它将等待调用返回数据。如果检索速度很慢,请考虑使其更快或仅按需绑定此数据的方法(例如,为用户添加按钮或复选框以设置列的Visible = true并引发标志以便检索数据)。使用AJAX,这样您的用户就会有一个加载指示符