2013-08-12 49 views
0

我有一個RADgrid,它有一個行單擊事件。這個事件有效,我看到在服務器端代碼中的斷點。Telerik Grid設置標準的ASP.NET標籤值

隨着行值我拉,我可以打一個數據庫,並得到我要找的結果,並將其分配給一個asp:標籤控件。

問題是,我從來沒有看到標籤屏幕上的值。我已驗證label.text屬性具有我想要的值,但無法將其顯示在屏幕上。

是否有一個命令,我需要觸發刷新頁面後,網格與服務器端控制完成?

+0

讓我看看你的GridView代碼,標籤和你的Rowclick事件! – zey

回答

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