Last post Nov 04, 2016 07:53 PM by codemovement.pk
Member
399 Points
1101 Posts
Nov 04, 2016 04:59 PM|asp.ambur|LINK
Hello
This is my Gridview Code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Field1" HeaderText="Field1" SortExpression="Field1" /> <asp:TemplateField HeaderText="Field2" SortExpression="Field2"> <EditItemTemplate> <asp:Label ID="ELabel1" runat="server" Text='<%# Bind("Field2") %>'></asp:Label> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Field2") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Field3" HeaderText="Field3" SortExpression="Field3" /> <asp:TemplateField HeaderText="Field4" SortExpression="Field4"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" onchange ="CheckNumber(this);" Text='<%# Bind("Field4") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Field4") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
My Output look like this below
I want out on Field5 like below (Field2 + Field3 - Field4)
Field5
55
45
100
All-Star
52161 Points
23255 Posts
Nov 04, 2016 05:05 PM|mgebhard|LINK
Just do the total in your SQL query.
http://stackoverflow.com/questions/14877797/how-to-sum-two-fields-within-an-sql-query
Nov 04, 2016 06:58 PM|asp.ambur|LINK
I want to do in asp.net page and C#
Contributor
2340 Points
807 Posts
Nov 04, 2016 07:53 PM|codemovement.pk|LINK
Hi,
Add row data bound event on grid and following code in rowbonud data event.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { int Field2 = Convert.ToInt32(e.Row.Cells[3].Text); int Field3 = Convert.ToInt32(e.Row.Cells[4].Text); int Field4 = Convert.ToInt32(e.Row.Cells[5].Text); e.Row.Cells[6].Text = (Field2 + Field3-Field4).ToString(); } }
Hope it helps.
Member
399 Points
1101 Posts
Show Total In Foruth Column Of Gridview
Nov 04, 2016 04:59 PM|asp.ambur|LINK
Hello
This is my Gridview Code
My Output look like this below
I want out on Field5 like below (Field2 + Field3 - Field4)
Field5
55
55
45
100
All-Star
52161 Points
23255 Posts
Re: Show Total In Foruth Column Of Gridview
Nov 04, 2016 05:05 PM|mgebhard|LINK
Just do the total in your SQL query.
http://stackoverflow.com/questions/14877797/how-to-sum-two-fields-within-an-sql-query
Member
399 Points
1101 Posts
Re: Show Total In Foruth Column Of Gridview
Nov 04, 2016 06:58 PM|asp.ambur|LINK
I want to do in asp.net page and C#
Contributor
2340 Points
807 Posts
Re: Show Total In Foruth Column Of Gridview
Nov 04, 2016 07:53 PM|codemovement.pk|LINK
Hi,
Add row data bound event on grid and following code in rowbonud data event.
Hope it helps.
Get more information: http://codemovement.pk
Thanks,