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 7947287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:23:20+00:00 2026-06-04T01:23:20+00:00

I have a GridView in ASP which I use for displaying products in a

  • 0

I have a GridView in ASP which I use for displaying products in a shopping cart.

I set the source of GridView the ShopDataSet and the columns Name, Price and Quantity are filled automatically.

What I want to achieve is a new column, added by me, which displays the cost of each row i.e. Cost = price * quantity;

How can I do this programatically, without executing a new query on the database?

I have to say that on Price and Quantity I set format like "${0}" for Price and "{0} piece(s)" for Quantity.

  • 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-06-04T01:23:22+00:00Added an answer on June 4, 2026 at 1:23 am

    You should populate your datasource programmatically.

    Get the results in a SqlDataReader and populate a DataTable with the results of the SqlDataReader.

    Now create a new DataTable with columns that match the output that you want including Cost in your case. Now iterate through each row of the 1st DataTable and add rows to the new DataTable with the cost calculation.

    For Example,

    DataTable oldTable = new DataTable();
    oldTable .Load(rdr); // where rdr is your SqlDataReader
    

    Now create your new table

    DataTable newTable = new DataTable();
    DataColumn noteID = new DataColumn("Cost", typeof(string));
    newTable.Columns.Add(noteID);
    //Add other columns
    foreach (DataRow row in oldTable .Rows)
    {
       DataRow newRow = newTable.NewRow();
       newRow["Cost"] = //your calculation
       ...
       ...
       newTable.Add(newRow);
    }
    

    Now set the DataSource of your grid to NewTable

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp:GridView which contains a asp:TextBox within a TemplateField. I would like
I have an ASP.NET(2.0 using C#) web app, in which I have a gridview.
I have asp:GridView displaying client requests using asp:SqlDataSource . I want to limit displayed
I have a Gridview <asp:GridView ID=GridView1 runat=server Width=400px AutoGenerateColumns=false OnSelectedIndexChanged=GridView1_SelectedIndexChanged1> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox
I have a asp:GridView with a HyperLinkField . It's DataNavigateUrlFormatString property is set to
So I have an ASP.NET page with two controls: a GridView which displays rows
I have an ASP.NET GridView that's bound to an ObjectDataSource (which is bound to
I have an asp.net gridview which is output as a table in HTML. There's
OK, so I understand how to use the ASP.net GridView control's paging. You set
I have a devexpress gridview within my asp.net page which has a filter row.

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.