Setting GridDropDownColumn DataSource server side

5 posts, 0 answers
  1. Michael
    Michael avatar
    51 posts
    Member since:
    Dec 2008

    Posted 24 Feb 2010 Link to this post

    After reviewing the documentation and help files I'm still doing something wrong.  I can actually get the dropdown to display correctly on and insert and edit modes. Everything is working there fine and saving correctly.  I'm having troubles with the value displaying on load. Here's what I've got.

    <telerik:GridDropDownColumn UniqueName="WatchdogFrequencyddl" ListTextField="Name" ListValueField="Watchdogfrequencyid" DataField="Watchdogfrequencyid" 
      SortExpression="Watchdogfrequencyid" HeaderText="Frequency" DropDownControlType="DropDownList" FooterText="RadComboBox column footer" > 
    </telerik:GridDropDownColumn>   
    protected void WDTGrid_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
       if (e.Item is GridEditableItem && e.Item.IsInEditMode) //fire for both edit and insert           
       {  
         GridEditableItem eeditItem = e.Item as GridEditableItem;  
         GridEditManager editMgr = editItem.EditManager;  
         GridDropDownListColumnEditor wdfEditor = editMgr.GetColumnEditor("WatchdogFrequencyddl") as GridDropDownListColumnEditor;  
          string s = DataBinder.Eval(editItem.DataItem, "Watchdogfrequencyid").ToString(); //the field should point to the ListValueField of the dropdown editor         
     
          wdfEditor.DataSource = getWatchdogFrequency();  
          wdfEditor.DataBind();  
          wdfEditor.SelectedValue = s;  
     
                    
     
        }  
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Feb 2010 Link to this post

    Hi,

    For the GridDropdownColumn to populate in the normal mode you need to assign a datasource .An alternative would be to  access the control  in the ItemDataBound event and set the value  as shown below:

    C#
      if (e.Item is GridDataItem) 
            { 
                GridDataItem dataItem = (GridDataItem)e.Item; 
     
                ((Literal)dataItem["CategoryNameDropdownColumn"].Controls[0]).Text = dataItem.GetDataKeyValue("CategoryName").ToString(); 
            } 


    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael
    Michael avatar
    51 posts
    Member since:
    Dec 2008

    Posted 25 Feb 2010 Link to this post

    When I add that to my ItemDataBound event. I get the 'Object reference not set to an instance of an object' error.  This is what I added. I know I'm missing something but just can't make the connection to what it is.
    Here's what I added to the ItemDataBound event:
                if (e.Item is GridDataItem)  
                {  
                    GridDataItem dataItem = (GridDataItem)e.Item;  
     
                    ((Literal)dataItem["WatchdogFrequencyddl"].Controls[0]).Text = dataItem.GetDataKeyValue("Name").ToString();  
                }  

    Where dataItem.GetDataKeyValue("Name"). is the value I want to display. The error fires on the line starting with ((Literal)dataItem.........

    Is there another way to set the datasource of a griddropdowncolumn on the server? Or is it best to set it clientside using a declarative clientside datasource?

    Thanks
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Feb 2010 Link to this post

    Hi,

    Please  make sure that you have added "Name" datafield to the DataKeyNames collection of RadGrid.

    ASPX:
        <MasterTableView DataSourceID="SqlDataSource1"  DataKeyNames="Name"  Name="Master"


    Thanks,
    Princy
  6. Tarang
    Tarang avatar
    2 posts
    Member since:
    Oct 2016

    Posted 05 Oct in reply to Michael Link to this post

    how the same condition fire for both edit and insert ? 

    please tell so that i can get help from your post..

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017