KNOWN PROBLEM: DataBinding: ‘Telerik.Web.UI.GridInsertionObject’ does not contain a property with the name 'XXX '

2 posts, 1 answers
  1. Ignjat
    Ignjat avatar
    13 posts
    Member since:
    Aug 2011

    Posted 01 Sep 2011 Link to this post

    Hello!

    I've been trying to find the workaround for the following problem for the last couple of hours, but without any success. I've found many of the possible solutions on the Internet, but none of them was solution to my problem.

    The problem occurs when I want to insert data into empty datasource. I've been able to find workarounds for RadComboBoxes, but not for the Textboxes. The error that is displayed is: "DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'OpciPrioritet'."

    Here is the code:

    .ascx (needed for the RadGrid)
    <table>
        <tr>
            <td>
                Nadređeni ticket:
            </td>
            <td colspan="3">
                <telerik:RadComboBox ID="rcbNadredeniTicket" AppendDataBoundItems="true" runat="server"
                    Width="455px">
                </telerik:RadComboBox>
            </td>
        </tr>
        <tr>
            <td>
                Prijavio:
            </td>
            <td colspan="3">
                <telerik:RadComboBox ID="rcbPrijavio" AppendDataBoundItems="true" runat="server"
                    Width="455px">
                </telerik:RadComboBox>
            </td>
        </tr>
        <tr>
            <td>
                Asset:
            </td>
            <td colspan="3">
                <telerik:RadComboBox ID="rcbAsset" AppendDataBoundItems="true" runat="server" Width="455px">
                </telerik:RadComboBox>
            </td>
        </tr>
        <tr>
            <td>
                Opći prioritet:
            </td>
            <td>
                <asp:TextBox ID="txtOpciPrioritet" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OpciPrioritet") %>'></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Tip:
            </td>
            <td>
                <telerik:RadComboBox ID="rcbTip" runat="server">
                </telerik:RadComboBox>
            </td>
        </tr>
        <tr>
            <td>
                Status:
            </td>
            <td>
                <telerik:RadComboBox ID="rcbStatus" runat="server">
                </telerik:RadComboBox>
            </td>
        </tr>
        <tr>
            <td>
                Datum prijave:
            </td>
            <td>
                <asp:TextBox ID="txtDatumPrijave" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DatumPrijave") %>'></asp:TextBox>
            </td>
            <td>
                Vrsta prijave:
            </td>
            <td>
                <telerik:RadComboBox ID="rcbVrstaPrijave" Text='<%# DataBinder.Eval(Container, "DataItem.VrstaPrijave") %>'
                    runat="server">
                </telerik:RadComboBox>
            </td>
        </tr>
        <tr>
            <td>
                Prioritet:
            </td>
            <td>
                <telerik:RadComboBox ID="rcbPrioritet" Text='<%# DataBinder.Eval(Container, "DataItem.Prioritet") %>'
                    runat="server">
                </telerik:RadComboBox>
            </td>
            <td>
                Deadline:
            </td>
            <td>
                <asp:TextBox ID="txtDeadline" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DatumDo") %>'></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Opis:
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtOpis" runat="server" TextMode="MultiLine" Width="455px" Height="200px"
                    Text='<%# DataBinder.Eval(Container, "DataItem.Opis") %>'></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Zatvoren ticket:
            </td>
            <td>
                <asp:CheckBox ID="chkZatvoren" runat="server" Checked='<%# CheckNull(DataBinder.Eval(Container, "DataItem.Zatvoren")) %>' />
            </td>
        </tr>
        <tr>
            <td>
                Opis zatvorenog ticketa:
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtOpisZatvorenog" runat="server" TextMode="MultiLine" Width="455px"
                    Height="200px" Text='<%# DataBinder.Eval(Container, "DataItem.OpisZatvoren") %>'></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Bilješke:
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtBiljeske" runat="server" TextMode="MultiLine" Width="455px" Height="200px"
                    Text='<%# DataBinder.Eval(Container, "DataItem.Biljeske") %>'></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnUpdate" Text="Spremi" runat="server" CommandName="Update" Visible='<%# !(DataItem is Telerik.Web.UI.GridInsertionObject) %>'>
                </asp:Button>
                <asp:Button ID="btnInsert" Text="Spremi" runat="server" CommandName="PerformInsert"
                    Visible='<%# DataItem is Telerik.Web.UI.GridInsertionObject %>'></asp:Button>
                  
                <asp:Button ID="btnCancel" Text="Odustani" runat="server" CausesValidation="False"
                    CommandName="Cancel"></asp:Button>
            </td>
        </tr>
    </table>


    .aspx.cs:
    protected void gvTicketi_ItemDataBound(object sender, GridItemEventArgs e)
    {
        int idFirma = Convert.ToInt16(Request.QueryString["idt"]);
     
        if ((e.Item is GridEditFormItem) && e.Item.IsInEditMode )
        {
            GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
     
            TSEntities db = new TSEntities();
            Ticket ticket = new Ticket();
            TicketAsset ticketAsset = new TicketAsset();
     
            RadComboBox rcbTip = (RadComboBox)userControl.FindControl("rcbTip");
            rcbTip.Items.Add(new RadComboBoxItem("Incident"));
            rcbTip.Items.Add(new RadComboBoxItem("Reklamacija"));
            rcbTip.Items.Add(new RadComboBoxItem("Nova funkcionalnost"));
            rcbTip.DataBind();
            rcbTip.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Tip') %>'";
     
            RadComboBox rcbStatus = (RadComboBox)userControl.FindControl("rcbStatus");
            rcbStatus.Items.Add(new RadComboBoxItem("New"));
            rcbStatus.Items.Add(new RadComboBoxItem("U radu"));
            rcbStatus.Items.Add(new RadComboBoxItem("On hold"));
            rcbStatus.Items.Add(new RadComboBoxItem("Pending"));
            rcbStatus.Items.Add(new RadComboBoxItem("Scheduled"));
            rcbStatus.Items.Add(new RadComboBoxItem("Canceled"));
            rcbStatus.Items.Add(new RadComboBoxItem("Completed"));
            rcbStatus.DataBind();
            rcbStatus.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Status') %>'";
     
            RadComboBox rcbVrstaPrijave = (RadComboBox)userControl.FindControl("rcbVrstaPrijave");
            rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Usmeno"));
            rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Telefon"));
            rcbVrstaPrijave.Items.Add(new RadComboBoxItem("E-mail"));
            rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Web"));
            rcbVrstaPrijave.DataBind();
            rcbVrstaPrijave.Text = "'<%# DataBinder.Eval(Container, 'DataItem.VrstaPrijave') %>'";
     
            RadComboBox rcbPrioritet = (RadComboBox)userControl.FindControl("rcbPrioritet");
            rcbPrioritet.Items.Add(new RadComboBoxItem("Low"));
            rcbPrioritet.Items.Add(new RadComboBoxItem("Normal"));
            rcbPrioritet.Items.Add(new RadComboBoxItem("High"));
            rcbPrioritet.Items.Add(new RadComboBoxItem("Odmah"));
            rcbPrioritet.DataBind();
            rcbPrioritet.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Prioritet') %>'";
     
            RadComboBox rcbNadredeniTicket = (RadComboBox)userControl.FindControl("rcbNadredeniTicket");
            var nadredenTicketList = (from t in db.Ticket
                                        select t).ToList();
     
            if (nadredenTicketList.Count > 0)
            {
                rcbNadredeniTicket.DataSource = from t in nadredenTicketList
                                                where t.idFirma == idFirma && t.Zatvoren == false
                                                select new { t.idTicket, t.idNadredeniTicket, OpisTicketa = t.idTicket + " - " + t.Opis };
     
                rcbNadredeniTicket.DataTextField = "OpisTicketa";
                rcbNadredeniTicket.DataValueField = "idTicket";
                rcbNadredeniTicket.Text = "'<%# DataBinder.Eval(Container, 'DataItem.idNadredeniTicket') %>'";
            }
     
            rcbNadredeniTicket.Items.Add(new RadComboBoxItem("Bez nadređenog ticketa", "0"));
            rcbNadredeniTicket.DataBind();
     
            RadComboBox rcbPrijavio = (RadComboBox)userControl.FindControl("rcbPrijavio");
            rcbPrijavio.DataSource = from k in db.Kontakt
                                     where k.idFirma == idFirma
                                     select new { k.idKontakt, kontaktNaziv = k.Ime + " " + k.Prezime };
     
            rcbPrijavio.Items.Add(new RadComboBoxItem("Bez kontakta", "0"));
            rcbPrijavio.DataTextField = "kontaktNaziv";
            rcbPrijavio.DataValueField = "idKontakt";
            rcbPrijavio.Text = "'<%# DataBinder.Eval(Container, 'DataItem.idKontakt') %>'";
            rcbPrijavio.DataBind();
     
            RadComboBox rcbAsset = (RadComboBox)userControl.FindControl("rcbAsset");
            var assetList = (from a in db.Asset
                             where a.idFirma == idFirma
                             select a).ToList();
     
            if (assetList.Count > 0)
            {
                var assets = from a in assetList
                             where a.idFirma == idFirma
                             select new { a.idAsset, Naziv = a.Naziv + " (" + a.Kontakt.Ime + " " + a.Kontakt.Prezime + ")" };
     
                rcbAsset.DataSource = assets;
                rcbAsset.DataTextField = "Naziv";
                rcbAsset.DataValueField = "idAsset";
                rcbAsset.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Naziv') %>'";
                rcbAsset.Items.Add(new RadComboBoxItem("Bez pridruženog asseta", "0"));
                rcbAsset.DataBind();
            }                            
             
             
            if (!e.Item.OwnerTableView.IsItemInserted)
            {
                int idTicket = Convert.ToInt32(editFormItem.GetDataKeyValue("idTicket"));
                ticket = db.Ticket.SingleOrDefault(t => t.idTicket == idTicket);
     
                string tip = ticket.Tip;
                rcbTip.Items.FindItemByText(tip).Selected = true;
     
                string status = ticket.Status;
                rcbStatus.Items.FindItemByText(status).Selected = true;
     
                string vrstaPrijave = ticket.VrstaPrijave;
                rcbVrstaPrijave.Items.FindItemByText(vrstaPrijave).Selected = true;
     
                string prioritet = ticket.Prioritet;
                rcbPrioritet.Items.FindItemByText(prioritet).Selected = true;
     
                int kontakt = Convert.ToInt32(ticket.idKontakt);
     
                if (ticket.idKontakt == null)
                {
                    rcbPrijavio.Items.FindItemByValue("0").Selected = true;
                }
                else
                {
                    rcbPrijavio.Items.FindItemByValue(kontakt.ToString()).Selected = true;
                }
     
                int nadredeniTicket = Convert.ToInt32(ticket.idNadredeniTicket);
                 
                if (ticket.idNadredeniTicket == null)
                {
                    rcbNadredeniTicket.Items.FindItemByValue("0").Selected = true;
                }
                else
                {
                    rcbNadredeniTicket.Items.FindItemByValue(nadredeniTicket.ToString()).Selected = true;
                }
     
                var ticketAssetCount = from ta in db.TicketAsset
                                       where ta.idTicket == idTicket
                                       select ta;                 
                                 
                if (ticketAssetCount.Count() > 0)
                {
                    ticketAsset = db.TicketAsset.SingleOrDefault(ta => ta.idTicket == idTicket);
     
                    int asset = Convert.ToInt32(ticketAsset.idAsset);
     
                    rcbAsset.Items.FindItemByValue(asset.ToString()).Selected = true;
                }
                else
                {
                    rcbAsset.Items.FindItemByValue("0").Selected = true;
                }
            }
        }
    }

    .aspx (only the needed snippet):
    <telerik:RadGrid ID="gvTicketi" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" CellSpacing="0" GridLines="None"
        onneeddatasource="gvTicketi_NeedDataSource"
        onitemdatabound="gvTicketi_ItemDataBound"
        oninsertcommand="gvTicketi_InsertCommand"
        onupdatecommand="gvTicketi_UpdateCommand">
        <MasterTableView DataKeyNames="idTicket" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
            <CommandItemSettings AddNewRecordText="Dodaj novi ticket" RefreshText="Prikaži sve tickete" />
            <Columns>
                <telerik:GridBoundColumn UniqueName="idTicket" HeaderText="Ticket" DataField="idTicket">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="idKontakt" HeaderText="Kontakt" DataField="idKontakt">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="idManager" HeaderText="Manager" DataField="idManager">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Opis" HeaderText="Opis" DataField="Opis">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="TicketNumber" HeaderText="Broj ticketa" DataField="TicketNumber">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="DatumPrijave" HeaderText="Datum prijave" DataField="DatumPrijave" DataFormatString="{0:dd.MM.yyyy.}">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="VrstaPrijave" HeaderText="Vrsta prijave" DataField="VrstaPrijave">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Tip" HeaderText="Tip" DataField="Tip">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Status" HeaderText="Status" DataField="Status">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Prioritet" HeaderText="Prioritet" DataField="Prioritet">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="OpciPrioritet" HeaderText="Opći prioritet" DataField="OpciPrioritet">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Deadline" HeaderText="Deadline" DataField="DatumDo" DataFormatString="{0:dd.MM.yyyy.}">
                </telerik:GridBoundColumn>
                <telerik:GridCheckBoxColumn UniqueName="Zatvoren" HeaderText="Zatvoren" DataField="Zatvoren">
                </telerik:GridCheckBoxColumn>
                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
                </telerik:GridEditCommandColumn>
                <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
                    ConfirmDialogType="RadWindow" ConfirmText="Brisanje ticketa!" />
            </Columns>
            <EditFormSettings UserControlName="UserControls/TicketUserControl.ascx" EditFormType="WebUserControl">
                <EditColumn UniqueName="EditCommandColumn1">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>


    Any help would be appreciated as this is pretty much urgent!
  2. Answer
    Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 02 Sep 2011 Link to this post

    Hi Ignjat,

    Please try the following DataBind expression:
    Text='<%# DataBinder.Eval(Container.DataItem, "DatumPrijave") %>'

    You need to change the other expressions as well using the same approach to get a working project.

    For a reference how to use DataBinder.Eval() method you could review the following msdn article.

    Please let us know whether it works or the issue still persists.

    All the best,
    Andrey
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top