从RadGrid访问代码隐藏中的RadComboBox

时间:2013-01-24 22:50:47

标签: c# asp.net sharepoint-2010 telerik telerik-grid

在从RadGrid编辑内联时,我无法抓取RadComboBox。当我尝试通过此GridEditableItem找到正确的控件时,我总是收到null。有谁能告诉我如何从我的代码中访问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>

my 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???
        }
    }

1 个答案:

答案 0 :(得分: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");

    }
}