12,400,556 members (61,871 online)
Rate this:
See more: , +
Hi
Lets say that I have a table with three columns. Name, Salary, Bonus.
Now I want to create a gridView to represent the data in the table with a fourth column contains the bonus calculation ( salary * bonus).
In other words, I will have a three columns table, and a four column gridView.

I Hope that any one can help me.
Posted 24-Feb-13 3:39am
Shanu2rick 24-Feb-13 9:52am

The best way to perform this task is by using Item Template in gridView designed by you. All you need to do is create four columns. Assign the values of the three column directly and the fourth column's programatically. I hope this help will sort you out with your help.
Sandeep Mewara 24-Feb-13 11:17am

Ok, so where are you stuck? What have you tried so far?

Rate this:

## Solution 2

try the following solution...
Once your retrieve data from database to DataTable the add one new column in the same data table like
Assume your datatable name is dt then write,
```dt.Columns.Add(new DataColumn("Total", typeof(decimal)));
foreach(DataRow dr in dt.Rows)
{
dr["Total"] = Convert.ToDecimal(dr["Salary"]) * Convert.ToDecimal(dr["Bonus"])
}

Gridview1.DataSource = dt;
GridView1.DataBind();
```

```<templatefield>
<itemtemplate>
<asp:lable id="lblTotal" runat="Sever" text="<%# Bind("Total") %>" xmlns:asp="#unknown" />
</itemtemplate>
</templatefield>
```
Rate this:

## Solution 1

first of all thank you for your interesting,
regarding the second comment by Sandeep Mewara, I read the data and made my calculation in a dataReader, but I don't know how to assign the value to a new column and and make the new column appear in the gridView.

what I am really trying to do is the following.
In the table I have one column holds the amount value which can be number of experience years, or it can be a percentage of bonus, or percentage of inflation.
in the second column I have the allowance field.
what I am trying to do is to read the second column and find the allowance type, then depending on the type of that allowance I can make some calculations for example:
if the allowance type is experience then I will multiply the allowance Amount which is number of years by a certain amount of money from another table depending on the job. and if the allownace type is bonus I have to multiply the amount by the salary in another table using C# code.

Thank you
Rate this:

## Solution 3

```SqlCommand cmd = new SqlCommand("SELECT * FROM RNDTABLE",con);
DataTable dt=new DataTable();
da.Fill(dt);

```GridView1.DataSource = dt;
GridView1.DataBind();```

Top Experts
Last 24hrsThis month
 OriginalGriff 335 Vincent Maverick Durano 220 ppolymorphe 155 Jochen Arndt 105 Richard Deeming 105
 OriginalGriff 6,848 ppolymorphe 2,940 Karthik Bangalore 2,737 Richard MacCutchan 2,077 F-ES Sitecore 2,052