This is a migrated thread and some comments may be shown as answers.

Access to GridDropDownListColumnEditor

1 Answer 249 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniela
Top achievements
Rank 1
Daniela asked on 07 Jan 2011, 05:42 PM

I can read the value of "grid column drop down"in the method "OnEditCommandRadGridProgramCategory. About e.Item.FindControl is null and also against the direct access via "GridDropDownColumnVirtualCategory.DataValueField" is null.

 The call to the method is via "CommandName = EditSelected.

 Can you help me please?


        <telerik:RadGrid ID="RadGridProgramCategory" 
        AutoGenerateColumns="false" 
        AllowAutomaticInserts="True" 
        AllowAutomaticUpdates="True" 
        AllowAutomaticDeletes="True" 
        OnEditCommand="OnEditCommandRadGridProgramCategory" 
        OnNeedDataSource="OnNeedDataSourceRadGridProgramCategory"
        GridLines="None"
        runat="server" 
        Width="350px">
    <Columns>
              <telerik:GridDropDownColumn HeaderText="Hauptkategorie" ColumnEditorID="GridDropDownColumnVirtualCategory" ListDataMember="VirtualCategoryId" UniqueName="VirtualCategoryId" DataField="VirtualCategoryId" ListTextField="VirtualCategoryName" ListValueField="VirtualCategoryId" />
              <telerik:GridDropDownColumn HeaderText="Unterkategorie" ColumnEditorID="GridDropDownColumnCategory" ListDataMember="CategoryId" UniqueName="CategoryId" DataField="CategoryId" ListTextField="CategoryName" ListValueField="CategoryId" />
              <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" />
            </Columns>
          </MasterTableView>
        </telerik:RadGrid>
        <telerik:GridDropDownListColumnEditor ID="GridDropDownColumnVirtualCategory" runat="server" DropDownStyle-Width="110px" />
        <telerik:GridDropDownListColumnEditor ID="GridDropDownColumnCategory" runat="server" DropDownStyle-Width="110px" />
        
protected void OnEditCommandRadGridProgramCategory(object sender, GridCommandEventArgs e)
{
  RadGrid radGrid = (RadGrid)sender;
  Control s0 = e.Item.FindControl(GridDropDownColumnVirtualCategory.ClientID);
  string s1 = GridDropDownColumnVirtualCategory.DataValueField;
  string s2 = GridDropDownColumnCategory.DataValueField;
}

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 10 Jan 2011, 05:14 PM
Hello Daniela,

Declarative column editors are provided for styling purposes only. You have an option of declaratively specifying the style of  your column editors through the markup, and thus enable approaches like ASP.NET Skins and Themes.  Thus, the GridDropDownListColumnEditor cannot be used as a reference to the DropDown or RadComboBox control in RaDGrid's edit form. If you need to programmatically access the dropdown that is initialized in the edited item, you need to use RadGrid's ItemDataBound event:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if(e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editItem = (GridEditableItem)e.Item;
        GridDropDownListColumnEditor dropDownEditor = (GridDropDownListColumnEditor)editItem.EditManager.GetColumnEditor("DropDownColumnUniqueName");
        dropDownEditor.ComboBoxControl.SelectedValue = "some value";
    }
}

Note how I programmatically access the edited item and find the respective column editor by the column's UniqueName. More information about this approach can be found in the following help topic.

Note that I cannot get a reference of the editor in the EditCommand event handler, as you are trying to do. EditCommand is the command that is fired before the edit item is initialized. It is fired just when you click an edit command button in a grid item. The actual edit item is initialized after RadGrid rebinds and is available in RadGrid's ItemDataBound event (raised for each databound item, including the edit items).
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
General Discussions
Asked by
Daniela
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or