Calculate a column in a Gridview based on data in another column of the same Girdview?

Anybody got any ideas? I'm stumped. I want a column in a gridview to take the value of another column in the same row as a parameter and run a query and then bind it. Like I said I'm stumped.



6/20/2008 6:10:21 PM 72751 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 52

I don't think you can pass the value of another column in the same row as a parameter and run a query and then bind it.  However, you could write a query with a calculated column from another field. 


Please mark replies that have helped you as answers.
6/20/2008 6:18:46 PM

Hi CoreslabBill,

You can do it in RowDataBound event of GridView control. Here is my sample. In my sample I will change the first column value according the seventh column.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)
            string class_id = e.Row.Cells[6].Text;     //get value from the seventh column
            e.Row.Cells[0].Text = GetData("select ClassName from [class] where ClassID=" + class_id).Tables[0].Rows[0][0].ToString();   
            //set the first column value from a query using that relevant value, here you can do any calculation to this value.


Qin Dian Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
6/25/2008 3:19:04 AM

 Hi Bill,

Can you elaborate a little more?
On Which Event do you want this?
A button_Click inside the Grid?


Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question.
View Blog
6/25/2008 4:09:08 AM


You could modify the datasource by adding a new datacolumn with the expression. Please refer this url. 


Always remember to click “Mark as Answer” on the post that helps you. Thank you!

6/25/2008 7:08:38 AM

Similar Artilces:

appending data from one column to another column in gridview
 Hi,I have 2 columns in this,Area    Areaunit100       sq.feet200       sq.yard400        meters  While showing area in gridview, i want to append its unit . Example 400 meters should be seen and not just 400<asp:BoundField DataField="area" HeaderText="AREA" SortExpression="area" />  Please Mark the post as "ANSWER" if it helps you One way is using template field, check this code..  <asp:TemplateField HeaderText="AREA"> <It...

to Calculated Columns, then to update another column in same table in ADO.NET
to get several Columns, then pass those Columns into  one function which will return  a result,then using the result to update another column in same table in ADO.NET, How can I do this? thanks. Hi   what ever information you given is not clear. so please give me  detail info.Ganesan  Clarity is required. Plz explain clearly wts u r requirement.Thank uBaba Thank uBabaPlease remember to click "Mark as Answer" on this post if it helped you. ...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Issue with Template Columns & Bound Columns while updating the data in a GridView control
Hi, I'm facing the below problem (In general, ObjectDataSource is driving me crazy ! ) I have a simple gridview control and an ObjectDataSource is used to populate the grid. I'm trying to update a row and the corresponding tableadapter methods & stored procedure are in place. Each row has 2 checkboxes and 2 textboxes in edit mode. When the change the values in edit mode and hit update, the checkbox values changed are saved into the Database properly, whereas the textbox values are not being saved. If the textbox column is a bound column then the column is updated with <NULL> in...

i have work on gridview that i have as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i
hi,i have work on gridview that i have as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i want display half of the data and remaining display like this.(ex: can i display like this,and one more thing is always the column size will constant. Try something like this: <asp:templatefield headertext="Link"> <itemtemplate> <asp:hyperlink id="HyperLink1" runat="server" navigateurl='<...

binding a gridview to xmldatasource gives "The data source for gridview gridview1 did not have any properties or attributes from which to generate columns. Ensure that your data source has columns
Greetings!  I am new to forum so feel free to point me to the proper resources or forums.  I am using Visual Studio 2005.  I have a simple web page with a gridview control and an xmldatasource control.  I am getting the above error.  Can someone point out why I am getting the above error and what I need to do to resolve it?  Thanks in advance. /////////////////////////////// default.aspx  <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="default.aspx.vb" Inherits="XMLwalkthroughVB._default" %&...

Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once?
 Hi Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once onto the grid? What I mean is some grid that 's as flexible as MS Excel grid for example.  Any suggestions will be very much appreciated.E The Repeater control is a highly customisable data presentation controlRohin.NET developerNever trust a computer you can't throw out a window. - Steve WozniakPlease remember to click on 'Mark as answer', if this post helped you......

Base DataGrid column contents on another column
Hi I have a DataGrid column that may contain a set number of values. Depending on the value of this column, I want another column to display LinkButtons that relate only to that value. That is, the LinkButtons in the second column must change dynamically, based on the value of the first column. Thanks Handle ItemDataBound for the grid, and manipulate the LinkButton column contents there. In what way do the linkbuttons neeed to change?JimMS MVP ASP.NET [VC++/MFC emeritus]Old Dog Learns New TricksPreferred programming language: cuneiform on clay tablets...

how to create a column based on other columns' data?
i need create a column A in table or datawindow or view using column B & C 's data this is the formula: A[0]=B[0]-C[0]; A[i]=A[i-1]+B[i]-C[i] (i>0); how to do it? thanks a lot. hi, thriller use one function from datawindows knowed with "cumulativesum()" this steps one 1. create one compute field 2. put this stament cumulativesum(b - c) good luck thanks a lot.that really'll take me much time to 'cumulativeSum' usage of functions. Adalberto Rua Aguirre <> wrote in message news:4BBMXYw...

Hide Gridview column based on the column value
I have a grid which i bind with values from Database. I have events to edit and update the grid. I am not using SqlDatasource to connect to DB. Rather i am doing the updating of the grid Programmatically. The Grid is populated based on a dropdown selection Gridview has 4 columns, LID(item template column) ,LVal (Item Template and an Edit Item template column), Lookupid (Item Template and an Edit Item template column) and "Edit" link 4 of 10 Dropdown selections have values in Column 3 (lookupid), rest dont. When they dont have values i want to hide that column 3. Of course i can ...

subtotal a column based on the uniqueness of another column
Hi, The requirement is very simple. Following is the structure of the report output: REGION         CLIENT  AMOUNT  ACCOUNT_NO. ------------------------------------------------------------------- SOUTHERN      ABC       1000        Acc_1 SOUTHERN      XYZ         500         Acc_1 SOUTHERN      PQR   &...

Move data from one column to another column and row
I need some help converting a table which has one row for each year.  Displaying the data so the each row will contain all of the information for the title and all of the years displayed in separate columns. I have a SQL Querry which returns the data looking like this (the querry is grouping by Title and by year, then adding up the quantity of rows): Basic Information needed for Life Insurance 25 2005 Basic Information needed for Life Insurance 45 2006 Ea Chairmans Conference 10 2005 EA Chairmans Conference Press Release 33 2005 EA Chairmans Conferenc...

Copy Data From One Datagrid Column To Another Column
Hi all, I am trying to copy data from one column in a datagrid to another column in the same datagrid. I am using buttons to do this, not the edit, update, cancel datagrid buttons. This is what I have been trying but with no luck :int RowCount;RowCount = 1;string DataValue;//while (RowCount < DataGrid1.Items.Count)//{// DataGrid1.SelectedIndex = RowCount;// DataGrid1.SelectedIndex = RowCount;// DataValue = DataGrid1.SelectedItem.Cells[4].Text;// DataGrid1.SelectedItem.Cells[3].Text = DataValue;} Help appreciated thanks. Try this <%@ Page Language="C#" %&...

GridView: Show/hide columns based on column name
I would like to show/hide columns of my GridView based on user events. When the user clicks on a specific button, I would like to show/hide certain columns based on the column's name.  I can't seem to get this working.  When I do GridViewName.Columns, it only allows me to use an index and not a string to find the column.I can easily show/hide the columns based on the index of the column, but I would rather not hardcode index values in my application.  If I were to add or remove a column at a later date, I would have to go back through the code to adjust the indexes. Any sugg...

Web resources about - Calculate a column in a Gridview based on data in another column of the same Girdview? -

‘Time’ Helps Users Calculate How Much Time They Have Spent On Facebook
Have you ever wondered exactly how much time you have spent on Facebook over the years? This calculator from Time may be able to answer that. ...

Calculate Marketing (@calculatemktg) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Startup and Private Valuations : How do you calculate the valuation in a startup with no need for funds ...
... ratio is appropriate for your business. But there's no standardized way to establish that, and certainly no formula by which you could calculate ...

Run Speeds - Track and log your workouts and calculate time, pace, speed and distance on the App Store ...
Get Run Speeds - Track and log your workouts and calculate time, pace, speed and distance on the App Store. See screenshots and ratings, and ...

calculate - Flickr - Photo Sharing!
Explore jekert gwapo's photos on Flickr. jekert gwapo has uploaded 7967 photos to Flickr.

Corbell calculates the costs of doubt
Corbell calculates the costs of doubt

Salvation Army developed 'matrix' to calculate payouts to abuse victims, commission hears
The Salvation Army took a "largely litigious approach" towards victims of horrific physical and sexual abuse, especially those who sought compensation ...

Nest-egg needs hard to calculate
Retirement saving is often like the federal budget. We target a reasonable number and hope it works out.

Calculate your income tax based on the ATO personal tax scale
JavaScript disabled. Please enable JavaScript to use My News, My Clippings, My Comments and user settings. New feature Personalise your news, ...

YouTube - How to use 12C Financial Calculator to calculate cash flow NPV and IRR
Hochgeladen am 12.12.2010 Vicinno 12C Financial Calculator app best emulates HP 12C Financial Calculator for iPhone, iPad, Mac, and Android, ...

Resources last updated: 1/6/2016 11:08:41 AM