Telerik Grid设置标准ASP.NET标签值

时间:2013-08-12 06:58:59

标签: telerik telerik-grid radgrid

我有一个RADgrid,上面有一个行点击事件。此事件有效,我在服务器端代码中看到了断点。

使用我拉的行值,我可以访问数据库并获得我正在寻找的结果并将其分配给asp:label控件。

问题是,我从未在标签的屏幕上看到这个值。我已经验证了label.text属性具有我想要的值,但是我无法在屏幕上显示它。

在使用服务器端控件完成网格后,是否需要触发刷新页面的命令?

1 个答案:

答案 0 :(得分:1)

请尝试使用以下代码段。

ASPX

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="Label1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
    </ClientSettings>
</telerik:RadGrid>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

ASPX.CS

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data1 = new[] {
          new { ID = 1, Name ="Name_1"},
          new { ID = 2, Name = "Name_2"},
          new { ID = 3, Name = "Name_1"},
          new { ID = 4, Name = "Name_4"},
          new { ID = 5, Name = "Name_1"}
      };

    RadGrid1.DataSource = data1;
}


protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (RadGrid1.SelectedItems.Count > 0)
    {
        GridDataItem selectedItem = (GridDataItem)RadGrid1.SelectedItems[0];
        // Perform Your Logic here
        Label1.Text = DateTime.Now.ToString();
    }
}

有关详细信息,请查看以下链接。 http://www.telerik.com/community/forums/aspnet-ajax/grid/grid-row-click-showing-value-in-asp-label.aspx