radgrid延迟加载单列
radgrid delay loading of a single column
我有一个带有两个不同数据库的 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)。
我认为你做不到。服务器代码是同步的,因此它一次一行,因此它将等待对 return 数据的调用。如果检索速度很慢,请考虑使其更快的方法或仅按需绑定此数据(例如,为您的用户添加一个按钮或复选框以设置该列的 Visible=true 并引发一个标志以便检索数据)。使用 AJAX 这样您的用户就会有一个加载指示符
我有一个带有两个不同数据库的 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)。
我认为你做不到。服务器代码是同步的,因此它一次一行,因此它将等待对 return 数据的调用。如果检索速度很慢,请考虑使其更快的方法或仅按需绑定此数据(例如,为您的用户添加一个按钮或复选框以设置该列的 Visible=true 并引发一个标志以便检索数据)。使用 AJAX 这样您的用户就会有一个加载指示符