2013-01-24 51 views
0

從RadGrid內聯編輯時,我無法抓取RadComboBox。當我試圖通過這個GridEditableItem找到正確的控件時,我總是收到null。任何人都可以拋出一些關於如何從我的代碼中訪問RadCombobox的指針嗎?在RadGrid的代碼隱藏中訪問RadComboBox

我ascx.cs文件:

<telerik:RadGrid runat="server" ID="grid_AccessRecords" 
    AllowPaging="True" 
    AllowSorting="True" 
    Visible="False" 
    Width="100%" 
    PageSize="25" 
    OnItemCommand="AccessRecordsGridOnItemCommand" 
    OnNeedDataSource="AccessRecordGridNeedDataSource"> 
    <PagerStyle Position="TopAndBottom" /> 
    <ClientSettings EnableRowHoverStyle="true" /> 
    <MasterTableView DataKeyNames="Id" AutoGenerateColumns="False" EditMode="EditForms"> 
     <Columns> 
      <telerik:GridTemplateColumn HeaderText="Eign" UniqueName="tmp_AccessGroup"> 
       <ItemTemplate> 
        <asp:label runat="server" ID="lbl_accessGroupName" Text='<%# Eval("AccessGroupName") %>' /> 
       </ItemTemplate> 
       <EditItemTemplate> 
        <telerik:RadComboBox runat="server" ID="combo_editAccessGroup"></telerik:RadComboBox> 
       </EditItemTemplate> 
      </telerik:GridTemplateColumn> 
      <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" EditText="edit" ButtonType="ImageButton" EditImageUrl="/_layouts/images/AFLSharepoint2010/Edit.gif" /> 
      <telerik:GridButtonColumn CommandName="Delete" Text="delete" ConfirmText="Are you sure?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" 
       ButtonType="ImageButton" UniqueName="DeleteColumn" ImageUrl="/_layouts/images/AFLSharepoint2010/Delete.gif" /> 
     </Columns> 
     <EditFormSettings ColumnNumber="1" CaptionDataField="Id" CaptionFormatString="derp"> 
     EditColumn ButtonType="ImageButton" InsertText="Save" UpdateText="Save" UniqueName="EditCommandColumn" CancelText="Cancel" /> 
     </EditFormSettings> 
    </MasterTableView> 
</telerik:RadGrid> 

我的CS文件:

protected void AccessRecordsGridOnItemCommand(object sender, GridCommandEventArgs e) 
    { 
     GridEditableItem editableItem = e.Item as GridEditableItem; 

     if (editableItem != null) 
     { 
      RadComboBox comboEditAccessGroup = (RadComboBox) editableItem.FindControl("combo_editAccessGroup"); 
      //TODO: find out why always null??? 
     } 
    } 
+0

Telerik有一個很棒的網站,可以學習如何使用他們的控件如果你使用Telerik編碼,我建議你開始查看他們詳細記錄的頁面[Telerik RadComboBox](http://www.telerik.com/help/aspnet-ajax/combobox-templates-accessing-controls.html) – MethodMan

回答

0

你應該能夠訪問您的組合框,如果你使用OnItemCreated方法來代替:

protected void AccessRecordsGrid_OnItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
{ 

    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
     //the item is in edit mode  
     GridEditableItem editedItem = e.Item as GridEditableItem; 

     RadComboBox comboEditAccessGroup = (RadComboBox)editedItem.FindControl("combo_editAccessGroup"); 

    } 
} 
+0

謝謝你的回答@Kwin,因爲現在我可以抓住我的RadComboBox :)雖然我有一個問題,奇怪的是,用我的方法,我已經能夠抓住RadTextBox沒有問題,但是當我試圖抓住RadComboBox我總是收到空。你可能知道爲什麼? – gardarvalur

+0

@gardarvalur我不完全確定爲什麼RadTextBox工作,但不是RadComboBox。有兩個Telerik演示[here](http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/multicolumneditform/defaultcs.aspx)和[here](http://demos.telerik.com/ aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultcs.aspx)似乎建議文本框的處理更容易。也許文本框是在更先進的控件(比如組合框)之前在頁面內創建的? – Kwin

相關問題