我有一个加载两个radgrids的按钮。第一个是“国家”(快速从db获取数据)。第二个是“城市”(从数据库慢慢获取数据)。在aspx.cs中它看起来像:
grdCities.DataSource = doWork1();
grdCities.DataBind();
grdCountries.DataSource = doWork2();
grdCountries.DataBind();
当相应网格的数据准备就绪时,有没有办法让它们彼此独立地分页? 我应该使用服务器端的线程和ajax将其发送到页面以及如何做到这一点吗?
答案 0 :(得分:1)
请创建新网页并尝试使用以下代码段。
<强> .ASPX 强>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<script src="Script/jquery-1.8.2.js"></script>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script>
$(document).ready(function () {
});
function testclick() {
var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
ajaxManager.ajaxRequest("RadGrid1");
ajaxManager.ajaxRequest("RadGrid2");
return false;
}
</script>
</telerik:RadCodeBlock>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" RequestQueueSize="10">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
<telerik:AjaxUpdatedControl ControlID="RadGrid2" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1" runat="server"></telerik:RadGrid>
<telerik:RadGrid ID="RadGrid2" runat="server"></telerik:RadGrid>
<asp:Button ID="Button1" runat="server" OnClientClick="return testclick();" />
</form>
</body>
</html>
<强> .ASPX.CS 强>
public partial class Forum : System.Web.UI.Page
{
protected void Page_Init(object source, System.EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
private void NewMethod()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Custom1", typeof(string));
dt.Rows.Add(1, "name1", "custom1");
dt.Rows.Add(2, "name2", "custom2");
dt.Rows.Add(3, "name3", "Radgrid1_" + DateTime.Now.ToString());
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
}
private void NewMethod2()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Custom1", typeof(string));
dt.Rows.Add(1, "name1", "custom1");
dt.Rows.Add(2, "name2", "custom2");
dt.Rows.Add(3, "name3", "Radgrid2_" + DateTime.Now.ToString());
RadGrid2.DataSource = dt;
RadGrid2.DataBind();
}
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
if (e.Argument == "RadGrid1")
{
NewMethod();
}
else if (e.Argument == "RadGrid2")
{
Thread.Sleep(5000);
NewMethod2();
}
}
}
如果有任何疑虑,请告诉我。
谢谢, Jayesh Goyani