从RadGrid中的代码隐藏中访问RadComboBox
问题描述:
从RadGrid内联编辑时,我在抓住RadComboBox时遇到麻烦.当我尝试通过此GridEditableItem查找正确的控件时,我总是收到null.有人可以给我一些如何从下面的代码访问RadCombobox的指针吗?
I´m having trouble grabbing RadComboBox when editing inline from a RadGrid. When I try to find the correct control through this GridEditableItem I always receive null. Can anyone throw me some pointers in how to access the RadCombobox from my code below?
我的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???
}
}
答
如果使用 OnItemCreated
方法代替,则应该可以访问组合框:
You should be able to access your combo box if you use the OnItemCreated
method instead:
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");
}
}