我的ASP.Net应用程序中有一个RadGrid,我将AllowPaging设置为True,PageSize设置为10,现在每个RadGridPage加载10个项目,这就是我想要的,但是只要按下Next Page按钮(Arrow)看起来按钮)没有任何加载和RadGrid变空。 我怎样才能让它正常工作?
protected void Page_Load(object sender, EventArgs e)
{
PopulateGridOnLoad();
}
private void PopulateGridOnLoad()
{
rgCustomers.DataSource = odsCustomers;
// your datasource type
rgCustomers.MasterTableView.VirtualItemCount = 28;
//your datasource type total/count
rgCustomers.CurrentPageIndex = rgCustomers.MasterTableView.CurrentPageIndex;
rgCustomers.Rebind();
}
protected void grdName_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
rgCustomers.DataSource = odsCustomers;
// your datasource type
rgCustomers.MasterTableView.VirtualItemCount = 28;
//your datasource type total/count
rgCustomers.CurrentPageIndex = rgCustomers.MasterTableView.CurrentPageIndex;
//Donot rebind here
}
protected void btnLoad_Click(object sender, EventArgs e)
{
odsCustomers.SelectParameters["CustomerFullName"].DefaultValue = txtFullName.Text;
odsCustomers.SelectParameters["CustomerMelliCode"].DefaultValue = txtMelliCode.Text;
odsCustomers.SelectParameters["CustomerHomeAddress"].DefaultValue = txtHomeAddressPart.Text;
odsCustomers.SelectParameters["CustomerWorkAddress"].DefaultValue = txtWorkAddressPart.Text;
rgCustomers.DataSource = odsCustomers;
rgCustomers.DataBind();
}
答案 0 :(得分:1)
您必须在设计中设置以下网格属性
<telerik:RadGrid ID="grdName"
AllowPaging="True"
AllowCustomPaging="True"
VirtualItemCount="0" PageSize="15" >
在load vb.net上填充网格
Private Sub PopulateGridOnLoad()
grdName.DataSource = source ' your datasource type
grdName.MasterTableView.VirtualItemCount = source.Total 'your datasource type total/count
grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex
grdName.Rebind()
End Sub
在加载c#.net
上填充网格private void PopulateGridOnLoad()
{
grdName.DataSource = source;
// your datasource type
grdName.MasterTableView.VirtualItemCount = source.Total;
//your datasource type total/count
grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex;
grdName.Rebind();
}
覆盖NeedDatasource vb.net
Protected Sub grdName_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdName.NeedDataSource
grdName.DataSource = source ' your datasource type
grdName.MasterTableView.VirtualItemCount = source.Total 'your datasource type total/count
grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex
'Donot rebind here
End Sub
覆盖NeedDatasource c#
protected void grdName_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
grdName.DataSource = source;
// your datasource type
grdName.MasterTableView.VirtualItemCount = source.Total;
//your datasource type total/count
grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex;
//Donot rebind here
}
答案 1 :(得分:1)
经过很长一段时间我找到了解决方案,问题涉及两个小问题:
1.我同时设置了DataSource(代码中)和DataSourceID(属性),但它们并没有很好地协同工作
2.我将AllowPaging和AllowCustomPaging都设置为true,当它们都是真的时都不起作用:)这是你知道的telerik团队,但他们很棒我开玩笑
答案 2 :(得分:0)
您需要定义“onNeedDataSource”radgrid事件,您可以在其中重置网格的数据源。
protected void RadGrid_NeedDataSource(object sender, EventArgs e)
{
IsNeedDataSource = true;
}
而不是在页面OnPreRender
事件中你应该像:
protected override void OnPreRender(object sender, EventArgs e)
{
DriverLinksGrid.DataSource = value;
DriverLinksGrid.DataBind();
}
我不是很害羞,也许你可以在OnNeedDataSource
事件中绑定数据。但DataBind()
方法可能无法从那里获得。