【问题标题】:Accessing RadComboBox in codebehind from a RadGrid从 RadGrid 访问代码隐藏中的 RadComboBox
【发布时间】:2013-01-24 22:50:47
【问题描述】:

从 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>

我的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???
        }
    }

【问题讨论】:

  • Telerik 有一个很棒的网站,可以学习如何使用他们的控件,如果您正在使用 Telerik 进行编码,我建议您开始查看他们有据可查的页面 Telerik RadComboBox

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


【解决方案1】:

如果您改用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");

    }
}

【讨论】:

  • 感谢您的回答@Kwin,因为现在我可以抓住我的 RadComboBox 了 :) 不过我有一个问题,奇怪的是,使用我上面的方法,我已经能够毫无问题地抓住 RadTextBox,但是当我尝试抓取 RadComboBox 时,我总是收到 null。你知道为什么吗?
  • @gardarvalur 我不完全确定为什么 RadTextBox 有效,但 RadComboBox 无效。有两个 Telerik 演示 herehere 似乎表明文本框更容易处理。也许文本框是在更高级的控件(如组合框)之前在页面中创建的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-01
  • 1970-01-01
  • 2011-02-28
  • 2012-01-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多