You must Sign In to post a response.
  • Category: ASP.NET

    Addition Two column in a grid view and show in third column

    I have Grid view and I have two columns. I want two columns will add and show result in third column.

    eg: price1 Price2 Price3
    1 2 3
    5 6 11

    We have three columns in the grid. one column is price1, price2 & price3

    price1 amount is bind in the gridview column and price2 amount is also bind in grid view column2 then these result will show in price3 column and these result will bind in the grid view as we are showing in the previous.

  • #652200
    There are many ways to achieve the solution
    1. You can write the code in row data bound event of grid view
    2. If you are using data table, before binding that table to grid view add a new column and store the sum of col1 & col2 in new column and then bind that table to grid view.
    3. If the data you are pulling from database then do it in database.

    I hoping that former solution swill help you

  • #652202
    Please check the following code:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
    <asp:TemplateField HeaderText="price1">
    <asp:Label ID="LblPrice1" runat="server" Text='<%#Eval("price1")%>'></asp:Label>
    <asp:TemplateField HeaderText="price2">
    <asp:Label ID="LblPrice2" runat="server" Text='<%#Eval("price2")%>'></asp:Label>
    <asp:TemplateField HeaderText="Total">
    <asp:Label ID="LblTotal" runat="server" Text='<%# Convert.ToInt32(Eval("price1")) + Convert.ToInt32(Eval("price2"))%>'></asp:Label>

    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #652215
    use query lik this

    select ud as id, sum (Mothly_rental-Balance) from @master group by ud

    bind it in third column

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.