This is a migrated thread and some comments may be shown as answers.

"FixedId" is neither a DataColumn nor a DataRelation for table

3 Answers 756 Views
Grid
This is a migrated thread and some comments may be shown as answers.
courtney shoell
Top achievements
Rank 1
courtney shoell asked on 15 Oct 2013, 10:29 AM
Hi,

I am using Rad-grid hierarchical. when i am trying to rebind the grid after update or insert. i am getting "FixedId" is neither a DataColumn nor a data Relation"  Here i added my design and code behind please let me know where i am going wrong.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" Skin="Black" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated"
    AllowSorting="True" AllowMultiRowSelection="False" OnItemCommand="RadGrid1_ItemCommand" AutoGenerateEditColumn="false"
    OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource" OnInsertCommand="RadGrid1_InsertCommand" OnDataBound="RadGrid1_DataBound"
    OnPreRender="RadGrid1_PreRender" >
 
    <MasterTableView DataKeyNames="TempAccountsId" ShowFooter="true" TableLayout="Fixed" AllowMultiColumnSorting="True" EditMode="InPlace" >
        <DetailTables>
            <telerik:GridTableView DataKeyNames="FixedId" CommandItemDisplay="Top"  TableLayout="Fixed" Name="Fixed" ShowFooter="true" EditMode="InPlace" AllowAutomaticUpdates="false">
                <Columns>
                    <telerik:GridTemplateColumn Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblFixedId" runat="server" Text='<%#Eval("FixedId") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderText="Edit" UniqueName="Edit" ItemStyle-Width="25px" HeaderStyle-HorizontalAlign="Center"
                        EditImageUrl="../Images/edit.gif" ItemStyle-HorizontalAlign="Center">
                    </telerik:GridEditCommandColumn>
                    <telerik:GridTemplateColumn HeaderText="Delete" UniqueName="Delete" HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="40px" ItemStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <asp:ImageButton runat="server" ID="imgdelete" OnClientClick="return confirm('Are you sure that you want to Delete?');"
                                ImageUrl="../Images/delete.gif" CommandName="Delete" CommandArgument="" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                     
                    <telerik:GridTemplateColumn UniqueName="Jan" HeaderText="Jan" HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="70px">
                        <ItemTemplate>
                            <asp:Label ID="lblJan" runat="server" Text='<%# string.Format("{0:n}", Convert.ToDecimal(Eval("Jan"))) %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtJanEdit" Width="70px" runat="server" MaxLength="11" Text='<%# string.Format("{0:n}", Convert.ToDecimal(Eval("Jan"))) %>' CssClass="AlgRgh"
                                onkeypress="javascript:return Allownumbersonly(event);" BorderWidth="1px"></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="txtJanInsert" runat="server" Width="70px" MaxLength="11" CssClass="AlgRgh"
                                onkeypress="javascript:return Allownumbersonly(event);" BorderWidth="1px"></asp:TextBox>
                        </InsertItemTemplate>
                        <FooterTemplate>
                            <asp:Label ID="lblJanFooter" runat="server"></asp:Label>
                        </FooterTemplate>
                    </telerik:GridTemplateColumn>
                    
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridTemplateColumn HeaderText="AccountId" UniqueName="TempAccountsId" Visible="false">
                <ItemTemplate>
                    <asp:Label ID="lblTempAccountsId" runat="server" Text='<%#Eval("TempAccountsId") %>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Account Number" UniqueName="AccountNumber" ItemStyle-Width="120px" HeaderStyle-Width="120px" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left">
                <ItemTemplate>
                    <asp:Label ID="lblAccountNumber" runat="server" Text='<%#Eval("AccountNumber") %>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Account Name" UniqueName="AccountName" ItemStyle-Width="140px" HeaderStyle-Width="140px" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left">
                <ItemTemplate>
                    <asp:Label ID="lblAccountName" runat="server" Text='<%#Eval("AccountName") %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lbltotalFooter" runat="server" Text="Total:"></asp:Label>
                </FooterTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderStyle-Width="60" UniqueName="Jan" HeaderText="" ItemStyle-HorizontalAlign="Right"
                HeaderStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right"
                Aggregate="Sum" DataField="Jan" FooterAggregateFormatString="{0:n}">
            </telerik:GridTemplateColumn>
           
 
        </Columns>
    </MasterTableView>
    <ClientSettings AllowKeyboardNavigation="true" EnableRowHoverStyle="true">
        
    </ClientSettings>
</telerik:RadGrid>

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            if (!e.IsFromDetailTable)
            {
                //DGeneral gen = new DGeneral();
                //RadGrid1.DataSource = gen.GetAccountDetailsbyTabName("Fixed");
                Dfixed fix = new Dfixed();
                RadGrid1.DataSource = fix.GetFixedAccountsDetails(Convert.ToInt32(Session["Propertyid"].ToString()), Convert.ToInt32(Session["BudgetYear"].ToString()));
            }
        }
 
protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
            Dfixed fix = new Dfixed();
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
            switch (e.DetailTableView.Name)
            {
                case "Fixed":
                    {
                        int AccountID = Convert.ToInt32(dataItem.GetDataKeyValue("TempAccountsId").ToString());
                        e.DetailTableView.DataSource = fix.GetFixedByAccountId(AccountID, Convert.ToInt32(Session["BudgetYear"].ToString()), Convert.ToInt32(Session["Propertyid"].ToString()));
                        break;
                    }
 
                case "OrderDetails":
                    {
                        //string OrderID = dataItem.GetDataKeyValue("OrderID").ToString();
                        //e.DetailTableView.DataSource = GetDataTable("SELECT * FROM [Order Details] WHERE OrderID = " + OrderID);
                        break;
                    }
            }
        }
 protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            string exepUpdate = "";
            try
            {
                if (e.CommandName.Equals(RadGrid.UpdateCommandName))
                {
                    if (e.Item.OwnerTableView.Name == "Fixed")
                    {
                        bool ResultSuccess = false;
                        Dfixed fix = new Dfixed();
                        GridEditableItem item = e.Item as GridEditableItem;
                        Label lblFixedId = (Label)item.FindControl("lblFixedId");
                        int GenId = Convert.ToInt32(lblFixedId.Text.Trim().ToString());
                        TextBox txtDescriptionEdit = (TextBox)item.FindControl("txtDescriptionEdit");
                        TextBox txtJanEdit = (TextBox)item.FindControl("txtJanEdit");
                        if (txtJanEdit.Text.Trim().ToString() != string.Empty)
                        {
                            Jan = Convert.ToDouble(txtJanEdit.Text.Trim().ToString());
                        }
                        
                        total = Jan + Feb + Mar + Apr + May + Jun + July + Aug + Sep + Oct + Nov + Dec;
 
                        long? Retablesqfeet = fix.GetPropertyRentalsqfeet(Convert.ToInt32(Session["Propertyid"].ToString()));
 
                        double? genpersqft = total / Retablesqfeet;
 
                        ResultSuccess = fix.EditFixedDetails(GenId, Jan, Feb, Mar, Apr, May, Jun, July, Aug, Sep, Oct, Nov, Dec, total, genpersqft, txtDescriptionEdit.Text.Trim().ToString());
                        if (ResultSuccess)
                        {
                             RadGrid1.Rebind();
 
                        }
                        else
                        {
                            DisplayMessage("Please Verify the values");
                            e.Canceled = true;
                        }
                    }
                }
            }
            catch (Exception)
            {
                exepUpdate = "Please Verify the values you have changed in editable fields";
            }
            finally
            {
                if (exepUpdate != "")
                {
                    e.Canceled = true;
                    DisplayMessage("Fixed Record cannot be Updated. Reason: " + exepUpdate.ToString());
                }
            }
 
 
 
        }

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Oct 2013, 11:22 AM
Hi ,

This erratic behavior is due to the fact that your FixedId column cannot access its required DataField. Please check your DataSource configuration closely and see if this DataField's exact name is "FixedId".
Hope this helps,please try and let me know.

Thanks,
Princy
0
Rob
Top achievements
Rank 1
answered on 12 Mar 2014, 04:19 PM
Hi There,

I ran into this issue as well and searched through all of the forum posts to no avail.  After further debugging I found that we were making a call to the Grid.DataBind() explicitly as well as at the wrong time.  This forced the grid into rebinding before it was ready and caused this cryptic error.  We come from many years of explicit databinding in code and transitioning to the NeedsDataSource/Rebind() approach has come with some pain such as this issue, although this binding approach of the grid is very very nice.  Hopefully sharing this here will help someone else in the future.

Regards,
Robert
0
Eyup
Telerik team
answered on 17 Mar 2014, 10:16 AM
Hello Rob,

Thank you for sharing your experience in this matter. I hope this information will prove helpful to other developers as well.

Generally, please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding


In cases when the grid should be rebound externally and exclusively, Rebind() should be used instead.

Regards,
Eyup
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
Grid
Asked by
courtney shoell
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rob
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or