RadGrid Inline Edit with dropdown

9 posts, 1 answers
  1. RB
    RB avatar
    126 posts
    Member since:
    Dec 2013

    Posted 17 Mar 2014 Link to this post

    I am implementing this demo: http://demos.telerik.com/aspnet-ajax/input/examples/common/datagrid/defaultcs.aspx
    I want a dropdown in the inline edit format. The user can select on value from the dropdown. How can I achieve this?

    Also, only this dropdown column has isEdit enabled. None of the other columns are editable. 
    GridTextBoxColumnEditor editor = manager.GetColumnEditor("CustomerID") as GridTextBoxColumnEditor;
                  editor.TextBoxControl.Enabled = false;

    Instead of doing the above for each column, can I state somehow that all columns have isEditable=false. Only the dropdown column is editable.
    Please help me.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Mar 2014 in reply to RB Link to this post

    Hi,

    Please have a look into the sample code snippet to achieve  your scenario.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" AutoGenerateEditColumn="true">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <telerik:RadDropDownList ID="RadDropDownList1" runat="server">
                            <Items>
                                <telerik:DropDownListItem Text="Item1" />
                                <telerik:DropDownListItem Text="Item2" />
                            </Items>
                        </telerik:RadDropDownList>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    Let me know if you have any concern.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. RB
    RB avatar
    126 posts
    Member since:
    Dec 2013

    Posted 18 Mar 2014 Link to this post

    Can you please provide me the c# code. 
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Mar 2014 in reply to RB Link to this post

    Hi,

    I guess that you want to make the GridBoundClumn as not editable. In order to achieve your scenario no need of any c# code. You can set the ReadOnly property of GridBoundColumn as true. The column will be displayed according to the settings of previous properties in browser mode but will not appear in the edit-form.

    please elaborate your requirement if it doesn't help.
    Thank,
    Shinu.
  6. RB
    RB avatar
    126 posts
    Member since:
    Dec 2013

    Posted 19 Mar 2014 in reply to Shinu Link to this post

    I apologise for not being precise. I want the C# code to add a dropdown in the inline edit format. 
  7. RB
    RB avatar
    126 posts
    Member since:
    Dec 2013

    Posted 19 Mar 2014 Link to this post

    I am adding both GridTextBoxColumnEditor and GridDropDownColumnEditor as follows:
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
            {          
                if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                {
                    if (!(e.Item is GridEditFormInsertItem))
                    {
                        GridEditableItem item = e.Item as GridEditableItem;
                        GridEditManager manager = item.EditManager;
                        //Adding columns that are not editable
                        GridTextBoxColumnEditor editor = manager.GetColumnEditor("Description") as GridTextBoxColumnEditor;
                        editor.TextBoxControl.Enabled = false;
                        editor.TextBoxControl.BackColor = System.Drawing.Color.Gray;
                        editor.TextBoxControl.ForeColor = System.Drawing.Color.Black;
     GridDropDownColumnEditor dropDownEditor = manager.GetColumnEditor("SourceSystemType") as GridDropDownColumnEditor;
    }
    }
    }
    Can you please guide me on how can I add a dropdown list while on Inline Edit, and bind it to the datasource. 
  8. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Mar 2014 in reply to RB Link to this post

    Hi,

    I guess you want to replace a textbox in edit mode to DropDownList. Please take a look at the following code snippet.

    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
      if (e.Item is GridEditableItem && e.Item.IsInEditMode && !(e.Item is GridEditFormInsertItem))              
      {
        GridEditableItem edit=(GridEditableItem)e.Item;
        TextBox txt = (TextBox)edit["GridColumn"].Controls[0];
        txt.Visible = false;
        DropDownList droplist = new DropDownList();
        droplist.DataSource = DataSource;
        droplist.DataTextField = "Name";
        droplist.DataValueField = "Name";
        droplist.DataBind();
        edit["GridColumn"].Controls.Add(droplist);               
      }
    }

    Thanks,
    Shinu
  9. Matt
    Matt avatar
    2 posts
    Member since:
    May 2015

    Posted 24 Jun 2015 in reply to Shinu Link to this post

    After you replace that textbox with DropDownList, how do you save the DropDownList value ?
  10. Matt
    Matt avatar
    2 posts
    Member since:
    May 2015

    Posted 24 Jun 2015 in reply to Matt Link to this post

    To clarify I'm using the EditMode on my RadGrid. The original textbox saves correctly but when I change the textbox to a DropDownList it no longer updates the value. I can't figure out how to assign the dropdownlist value to my original gridboundcolumn
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017