0

我正在尝试在后面的代码中对 RadGrid 控件和标签进行 Ajaxify。这是我的代码。但是当 RadGrid 更改时,标签值不会刷新。你能告诉我这里有什么问题吗?

感谢您的任何帮助。

                    <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); 
            } 
        } 
    }
4

2 回答 2

0

尝试不使用加载面板的重载:

RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, lblName);

如果这仍然不起作用,请尝试以下操作:

ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(RadGrid1);
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(lblName);
于 2012-04-18T20:09:34.593 回答
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 的页面大小,那么它也会更新标签文本。

于 2012-04-19T06:28:27.707 回答