RadGrid Model Binding for Custom Edit Forms

2 posts, 0 answers
  1. Angelo
    Angelo avatar
    4 posts
    Member since:
    May 2016

    Posted 05 Jul 2016 Link to this post


    Trying to gather some info on how to bind the model to a RadGrid when in Edit mode for a dropdown list (or even a RadDropDownList).

    I have the following markup:

    <telerik:RadGrid ID="rgTest" runat="server"
        PageSize="10" >
        <PagerStyle Mode="NextPrevAndNumeric" />
        <MasterTableView AutoGenerateColumns="false"
            <CommandItemSettings ShowAddNewRecordButton="false" />
                    ButtonCssClass="btn btn-primary btn-sm">
                <telerik:GridTemplateColumn UniqueName="Id" HeaderText="ID">
                        <asp:Label ID="lblID" runat="server" Text='<%# Item.Id %>'></asp:Label>
                <telerik:GridTemplateColumn UniqueName="TestTitle" HeaderText="Title">
                        <asp:Label ID="lblTestTitle" runat="server" Text='<%# Item.TestTitle %>'></asp:Label>
                <telerik:GridTemplateColumn UniqueName="TestType" HeaderText="Type">
                        <asp:Label ID="lblTestType" runat="server" Text='<%# Item.TestType %>'></asp:Label>
            <EditFormSettings EditFormType="Template">
                <FormStyle />
                    <label for="txtTestTitle" class="col-md-4 control-label">Title</label>
                    <asp:TextBox ID="txtTestTitle" runat="server" ClientIDMode="Static" Text='<%# BindItem.TestTitle %>' CssClass="form-control" autocomplete="off"></asp:TextBox>
                    <label for="ddlType" class="col-md-4 control-label">Type</label>
                    <asp:DropDownList ID="ddlType" runat="server" Width="100%" CssClass="form-control" >

    My code behind as follows:

    public IQueryable<Model.TestData> GetData()
        DbContext ctx = new DbContext();
        return (from c in ctx.TestData
           select c).OrderBy(a => a.Id);
    public void UpdateWebProjectRequest(int Id)
        using(DbContext ctx = new DbContext())
            Model.TestData td = ctx.TestData.Where(a => a.Id == Id).FirstOrDefault();
            if (ModelState.IsValid)
    protected void rgTest_ItemDataBound(object sender, GridItemEventArgs e)
        if(e.Item is GridEditableItem && e.Item.IsInEditMode)
            GridEditableItem editItem = (GridEditableItem)e.Item;
            // Populate the DropdownList here.
            DropDownList ddlType = (DropDownList) editItem.FindControl("ddlType");
            // Some method here to load the dropdownlist.
            var list = new List<Models.TestTypes>();
            ddlType.DataSource = lst;
            ddlType.DataValueField = "TypeId";
            ddlType.DataTextField = "TypeName";

            ddlType.SelectedValue = DataBinder.Eval(editItem.DataItem, "TestType").ToString();


    The issue I am having is that when I changed the value in the dropdownlist and invoke an update command, the new value selected on the dropdownlist is not being propagated to the model, hence, the correct data is not being saved.

    I've looked at the article in this link:


    But I am not able to figure out how to bind the dropdownlist value properly.

    Any suggestions or ideas would be appreciated.




  2. Viktor Tachev
    Viktor Tachev avatar
    2499 posts

    Posted 08 Jul 2016 Link to this post

    Hello Angelo,

    Please examine the following article that describes in detail how you can use RadGrid and Model Binding.

    Viktor Tachev
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top