How do I get a reference to a GridDropDownColumn within Grid

4 posts, 1 answers
  1. Dan
    Dan avatar
    21 posts
    Member since:
    Nov 2008

    Posted 08 Aug 2008 Link to this post

    Good day,

    I'm using the ASP.NET ajax grid version 2008.1.619.35. I'm trying to get a reference to a GridDropDownColumn with in my grid during edit mode.

    I receive the following complier error message

    "Error 14 Cannot convert type 'System.web.UI.Control' to 'Telerik.web.UI.GridDropDownColumn'

    Here is my code

    protected void RadGrid1_EditCommand(object source, GridCommandEventArgs e)  
    {  
           //Is it a GridDataItem  
           if (e.Item is GridDataItem)  
           {  
     
               //Get the instance of the right type  
               GridDataItem dataBoundItem = e.Item as GridDataItem;  
               if (dataBoundItem.OwnerTableView.Name == "OrderHeader")  
               {  
                      GridDropDownColumn ddlStatus =(GridDropDownColumn) dataBoundItem.FindControl("Status");  
                        if (Convert.ToInt16(dataBoundItem["OrderStatusID"].Text) == 1)  
                        {  
        
                            if (e.Item.Edit)  
                            {  
                               Debug.Write("Edit Mode!);  
     
                            }  
                        }  
                        else 
                        {  
                            ddlStatus.ReadOnly = true;  
                        }  
                    }  
                }  
            }  
        } 

    Thanks
  2. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 11 Aug 2008 Link to this post

    Hello Twalker,

    See the example's source below which illustrates how you can reference the GridDropDownColumn control (RadComboBox by default) in edit mode:

    http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/AccessingCellsAndRows/DefaultCS.aspx

    Regards,
    Konstantin Petkov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Aug 2008 Link to this post

    Hi Twalker,

    I am not sure whether this is what you needed. Set OrderStatusID as the DataKeyName and then depending on the datakeyvalue you can enable or disable the ComboBox in the GridDropDownColumn in the edit mode.

    ASPX:
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderStatusID" > 
                        <Columns> 
                           
                            <telerik:GridDropDownColumn DataSourceID="SqlDataSource1" HeaderText="DropCol"  UniqueName="Dropcol" ListTextField="LastName" ListValueField="LastName" ></telerik:GridDropDownColumn> 
                        //  .. 
                        </Columns> 

    CS:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            
            if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
            { 
                GridEditFormItem editedItem = (GridEditFormItem)e.Item; 
                string strTxt = editedItem.GetDataKeyValue("OrderStatusID").ToString(); 
                if (strTxt =="1") 
                { 
                     //Access the RadCombobox here 
                    RadComboBox combo = (RadComboBox)editedItem["Dropcol"].Controls[0]; 
                    
                } 
                
            } 
           
        } 


    Regards
    Shinu.
  4. Elavarasan
    Elavarasan avatar
    1 posts
    Member since:
    Sep 2017

    Posted 22 Sep 2017 in reply to Konstantin Petkov Link to this post

    Hi

    I have Following error on rgDynamic.Rebind(); when the line is processing its going to itemcreated event(In this event using GridDropDownListColumnEditor editor = editMan.GetColumnEditor(ColumnName) as GridDropDownListColumnEditor;
                            DropDownList ddList = new DropDownList();
                            ddList = editor.DropDownListControl; lines for assign source for Dropdown)

     

     

    System.NullReferenceException was unhandled by user code
      HResult=-2147467261
      Message=Object reference not set to an instance of an object.
      Source=App_Web_sj2f5coe
      StackTrace:
           at WizardClient.rgDynamic_ItemCreated(Object sender, GridItemEventArgs e) in c:\Elavarasan\release-40\WebMaster\Common\WizardClient.aspx.cs:line 653
           at Telerik.Web.UI.RadGrid.OnItemCreated(GridItemEventArgs e)
           at Telerik.Web.UI.RadGrid.CallOnItemCreated(GridItemEventArgs e)
           at Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows)
           at Telerik.Web.UI.GridItemBuilder.InitializeItem(Int32 dataSourceIndex, String& nextItemHierarchicalIndex, Boolean& itemIsInEditMode)
           at Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group)
           at Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls)
           at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)
           at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
           at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
           at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
           at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
           at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
           at Telerik.Web.UI.GridTableView.PerformSelect()
           at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
           at Telerik.Web.UI.GridTableView.DataBind()
           at Telerik.Web.UI.RadGrid.DataBind()
           at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason)
           at Telerik.Web.UI.RadGrid.Rebind()
           at WizardClient.rgDynamic_PreRender(Object sender, EventArgs e) in c:\Elavarasan\release-40\WebMaster\Common\WizardClient.aspx.cs:line 550
           at System.Web.UI.Control.OnPreRender(EventArgs e)
           at System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)
           at Telerik.Web.UI.RadCompositeDataBoundControl.OnPreRender(EventArgs e)
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException: 

        protected void rgDynamic_PreRender(object sender, EventArgs e)
        {
            if (!rgDynamic.MasterTableView.IsItemInserted)
            {


                foreach (GridDataItem dataItem in rgDynamic.MasterTableView.Items)
                {
                    //if (dataItem is GridEditableItem)
                    {
                        dataItem.Edit = true;
                    }
                  
                }
                if (rgDynamic.MasterTableView.Items.Count > 0)
                    
                    rgDynamic.Rebind();
            }

    }

Back to Top