Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6103081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:41:16+00:00 2026-05-23T13:41:16+00:00

I have a gridview that is bound to a datasoure on page load. The

  • 0

I have a gridview that is bound to a datasoure on page load. The datasource is connected to various other database tables, ie. datasourceItem.relatedEntity

There is a column in the gridview whose value is dependent upon the sum of a certain field in all related relatedEntities.

So dataSourceItem has a one to many relationship with relatedEntity, and I need to sum the value from a specific column in all related relatedEntities. I want to do this as simply as possible, and I know this syntax is wrong, but this is kind of what I wanted to do:

Markup:

<asp:TemplateField HeaderText="Sum">
     <ItemTemplate>
         <asp:Label ID="lblSum" runat="server" Text='<%# Bind("relatedEntity.ColumnName").Sum() %>' />
     </ItemTemplate>
</asp:TemplateField>

Code-behind (databinding):

myGridview.DataSource = from ds in DataContext.dataSource
                        where ds.Id == selectId
                        select ds;
myGridview.DataBind();

I want to keep the amount of code to a minimum, so if this is at all possible, please help me figure out how. To be clear, the line of code I want to make work is this:

'<%# Bind("relatedEntity.ColumnName").Sum() %>'

Or at least something to that effect. I don’t necessarily have to use the Sum() method… if there is a different/better way of handling this, feel free to let me know

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:41:17+00:00Added an answer on May 23, 2026 at 1:41 pm

    First you need to use Eval instead of Bind.
    Next, you need to cast the evaluated expression to your EntityCollection type

    <asp:Label ID="lblSum" runat="server" Text='<%# ((System.Data.Objects.DataClasses.EntityCollection<relatedEntityItemType>)Eval("relatedEntity")).Sum(i=>i.ColumnName) %>'></asp:Label>
    

    Also you need to the proper imports <%@ Import Namespace="YourEntitiesNamespace" %>
    and System.Data.Entity

    Edit:
    If the page is doesn’t compile, this is needed in web.config

    <compilation targetFramework="4.0">
         <assemblies>
         <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>            
          </assemblies>
    </compilation>
    

    Also you can get rid off the full name of the type using the import directive

    <%@ Import Namespace="..entities.." %>
    <%@ Import Namespace="System.Data.Objects.DataClasses" %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this page with a GridView control inside that's bound to database. GridView
I have a gridview that is bound to a datasource on a Windows Form
I have a gridview that is bound to a datasource (Windows Forms, VB.NET). One
In my website, I have a gridview which has datasource dynamically bound from database
I have a ListView with a GridView that's bound to the properties of a
I have a gridview control that has on onclick event bound to every cell.
I have a GridView bound to an ICollection<UserAnswer> that needs to show two columns:
I have a gridview that is using a LinqDataSource for it's datasource. I've added
I have a gridview bound to a sql server datasource. I am currently moving
I have a GridView that is bound to an ObjectDataSource that is calling a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.