我正在尝试Ajaxify RadGrid控件和代码背后的标签。这是我的代码。但RadGrid更改时,Label值不会刷新。你能告诉我这里有什么问题吗?
感谢您的帮助。
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false">
<MasterTableView>
<Columns>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
<div id="div1" runat="server">
<table id="table1" runat="server" >
<tr>
<td align="center">
<asp:Label ID="lblName" runat="server" Font-Bold="true"> </asp:Label>
</td>
</tr>
</table>
</div>
代码背后。
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, lblName, null);
}
}
}
答案 0 :(得分:0)
尝试不使用加载面板的重载:
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, lblName);
如果仍然无效,请尝试以下方法:
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(RadGrid1);
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(lblName);
答案 1 :(得分:0)
请查看以下代码段或演示。 这对我来说是正确的。 如果有任何问题,请告诉我。
的.aspx
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
AllowPaging="True" OnPreRender="RadGrid1_PreRender" AutoGenerateColumns="false">
<PagerStyle AlwaysVisible="true" />
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
.aspx.cs
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
DateTime dt = new DateTime();
dynamic data = new[] {
new { ID = 1, Name ="Name1", customdate=dt,NO = 11.00},
new { ID = 2, Name = "Name2", customdate=dt,NO = 11.00},
new { ID = 3, Name = "Name3", customdate=dt,NO = 11.00},
new { ID = 4, Name = "Name4", customdate=dt.AddYears(2011),NO = 11.44},
new { ID = 5, Name = "Name5", customdate=dt,NO = 10.4}
};
RadGrid1.DataSource = data;
}
protected void Page_Load(object sender, EventArgs e)
{
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, Label1, null);
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
通过上面的示例,如果更改radgrid的pagesize,那么它也会更新标签文本。