473,395 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Gridview Calculation

parshupooja
159 100+
Hi all,

I need help. I am using asp.net C# . I have binded gridview with 5 columns. I have Dropdownlist in 4 columns Morning in, morning out, afternoon in and afternoon out and label in 5 column named as totalwhere i want to show calculation(morningout-morningin+afternoonout-afternoonin) but whenever i try to run this i get error in bolded section that "input string is not in correct format". However I have acheived this calculation on Gridview Databound event if I use Textboxes instead of Dropdowns.
protected void gvOnRowDataBound(object sender, GridViewRowEventArgs e)
{

if (GridView1.Rows.Count > 0)
{
foreach (GridViewRow grdts in GridView1.Rows)
{ DropDownList labelmin = (DropDownList)grdts.FindControl("DropDownList1");
DropDownList labelmout = (DropDownList)grdts.FindControl("DropDownList2");
DropDownList labelain = (DropDownList)grdts.FindControl("DropDownList3");
DropDownList labelaout = (DropDownList)grdts.FindControl("DropDownList4");
Label labelTotalHr = (Label)grdts.FindControl("lblTotalHr");
Label lbltotal = (Label)grdts.FindControl("lblTotal");

int hr = (Int32.Parse(labelmout.SelectedValue.Trim()) - Int32.Parse(labelmin.SelectedValue.Trim())) + (Int32.Parse(labelaout.SelectedValue.Trim()) - Int32.Parse(labelain.SelectedValue.Trim()));
labelTotalHr.Text = hr.ToString();
}
}


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="gvOnRowDataBound" CellPadding="6" CssClass="GridStyle" Width="600" ShowFooter="True" OnDataBound="TextBox1_SelectedIndexChanged" OnDataBinding="GridView1_DataBinding" OnSelectedIndexChanged="GridView1_SelectedIndexCha nged">
<RowStyle CssClass="GridItem" />
<AlternatingRowStyle CssClass="GridAltItem" />
<Columns>
</asp:TemplateField>
<asp:TemplateField HeaderText="Morning In">

<ItemTemplate>
<asp:DropDownList runat="server" id=DropDownList1 SelectedValue='<%# Bind("MorningIn") %>'>
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="1">1 AM</asp:ListItem>
<asp:ListItem Value="2">2 AM</asp:ListItem>
<asp:ListItem Value="3">3 AM</asp:ListItem>
<asp:ListItem Value="4">4 AM</asp:ListItem>
<asp:ListItem Value="5 ">5 AM</asp:ListItem>
<asp:ListItem Value="6">6 AM</asp:ListItem>
<asp:ListItem Value="7 ">7 AM</asp:ListItem>
<asp:ListItem Value="8">8 AM</asp:ListItem>
<asp:ListItem Value="9">9 AM</asp:ListItem>
<asp:ListItem Value="10">10 AM</asp:ListItem>
<asp:ListItem Value="11">11 AM</asp:ListItem>
<asp:ListItem Value="12">12 AM</asp:ListItem>
<asp:ListItem Value="13">1 PM</asp:ListItem>
<asp:ListItem Value="14">2 PM</asp:ListItem>
<asp:ListItem Value="15">3 PM</asp:ListItem>
<asp:ListItem Value="16">4 PM</asp:ListItem>
<asp:ListItem Value="17">5 PM</asp:ListItem>
<asp:ListItem Value="18">6 PM</asp:ListItem>
<asp:ListItem Value="19">7 PM</asp:ListItem>
<asp:ListItem Value="20">8 PM</asp:ListItem>
<asp:ListItem Value="21">9 PM</asp:ListItem>
<asp:ListItem Value="22">10 PM</asp:ListItem>
<asp:ListItem Value="23">11 PM</asp:ListItem>
<asp:ListItem Value="24">12 PM</asp:ListItem>
</asp:DropDownList>

</ItemTemplate>
<HeaderTemplate>
Morning
<br />
In<br />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Out">
<ItemTemplate>
<asp:DropDownList runat="server" id=DropDownList2 SelectedValue='<%# Bind("MorningOut") %>'>
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="1 ">1 AM</asp:ListItem>
<asp:ListItem Value="2">2 AM</asp:ListItem>
<asp:ListItem Value="3">3 AM</asp:ListItem>
<asp:ListItem Value="4">4 AM</asp:ListItem>
<asp:ListItem Value="5 ">5 AM</asp:ListItem>
<asp:ListItem Value="6">6 AM</asp:ListItem>
<asp:ListItem Value="7 ">7 AM</asp:ListItem>
<asp:ListItem Value="8">8 AM</asp:ListItem>
<asp:ListItem Value="9">9 AM</asp:ListItem>
<asp:ListItem Value="10">10 AM</asp:ListItem>
<asp:ListItem Value="11">11 AM</asp:ListItem>
<asp:ListItem Value="12">12 AM</asp:ListItem>
<asp:ListItem Value="13">1 PM</asp:ListItem>
<asp:ListItem Value="14">2 PM</asp:ListItem>
<asp:ListItem Value="15">3 PM</asp:ListItem>
<asp:ListItem Value="16">4 PM</asp:ListItem>
<asp:ListItem Value="17">5 PM</asp:ListItem>
<asp:ListItem Value="18">6 PM</asp:ListItem>
<asp:ListItem Value="19">7 PM</asp:ListItem>
<asp:ListItem Value="20">8 PM</asp:ListItem>
<asp:ListItem Value="21">9 PM</asp:ListItem>
<asp:ListItem Value="22">10 PM</asp:ListItem>
<asp:ListItem Value="23">11 PM</asp:ListItem>
<asp:ListItem Value="24">12 PM</asp:ListItem>
</asp:DropDownList> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="In">
<ItemTemplate>
<asp:DropDownList runat="server" id=DropDownList3 SelectedValue='<%# Bind("AfternoonIn") %>'>
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="1 ">1 AM</asp:ListItem>
<asp:ListItem Value="2">2 AM</asp:ListItem>
<asp:ListItem Value="3">3 AM</asp:ListItem>
<asp:ListItem Value="4">4 AM</asp:ListItem>
<asp:ListItem Value="5 ">5 AM</asp:ListItem>
<asp:ListItem Value="6">6 AM</asp:ListItem>
<asp:ListItem Value="7 ">7 AM</asp:ListItem>
<asp:ListItem Value="8">8 AM</asp:ListItem>
<asp:ListItem Value="9">9 AM</asp:ListItem>
<asp:ListItem Value="10">10 AM</asp:ListItem>
<asp:ListItem Value="11">11 AM</asp:ListItem>
<asp:ListItem Value="12">12 AM</asp:ListItem>
<asp:ListItem Value="13">1 PM</asp:ListItem>
<asp:ListItem Value="14">2 PM</asp:ListItem>
<asp:ListItem Value="15">3 PM</asp:ListItem>
<asp:ListItem Value="16">4 PM</asp:ListItem>
<asp:ListItem Value="17">5 PM</asp:ListItem>
<asp:ListItem Value="18">6 PM</asp:ListItem>
<asp:ListItem Value="19">7 PM</asp:ListItem>
<asp:ListItem Value="20">8 PM</asp:ListItem>
<asp:ListItem Value="21">9 PM</asp:ListItem>
<asp:ListItem Value="22">10 PM</asp:ListItem>
<asp:ListItem Value="23">11 PM</asp:ListItem>
<asp:ListItem Value="24">12 PM</asp:ListItem>
</asp:DropDownList> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Out">
<ItemTemplate>
<asp:DropDownList runat="server" id=DropDownList 4 SelectedValue='<%# Bind("AfternoonOut") %>' >
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="1 ">1 AM</asp:ListItem>
<asp:ListItem Value="2">2 AM</asp:ListItem>
<asp:ListItem Value="3">3 AM</asp:ListItem>
<asp:ListItem Value="4">4 AM</asp:ListItem>
<asp:ListItem Value="5 ">5 AM</asp:ListItem>
<asp:ListItem Value="6">6 AM</asp:ListItem>
<asp:ListItem Value="7 ">7 AM</asp:ListItem>
<asp:ListItem Value="8">8 AM</asp:ListItem>
<asp:ListItem Value="9">9 AM</asp:ListItem>
<asp:ListItem Value="10">10 AM</asp:ListItem>
<asp:ListItem Value="11">11 AM</asp:ListItem>
<asp:ListItem Value="12">12 AM</asp:ListItem>
<asp:ListItem Value="13">1 PM</asp:ListItem>
<asp:ListItem Value="14">2 PM</asp:ListItem>
<asp:ListItem Value="15">3 PM</asp:ListItem>
<asp:ListItem Value="16">4 PM</asp:ListItem>
<asp:ListItem Value="17">5 PM</asp:ListItem>
<asp:ListItem Value="18">6 PM</asp:ListItem>
<asp:ListItem Value="19">7 PM</asp:ListItem>
<asp:ListItem Value="20">8 PM</asp:ListItem>
<asp:ListItem Value="21">9 PM</asp:ListItem>
<asp:ListItem Value="22">10 PM</asp:ListItem>
<asp:ListItem Value="23">11 PM</asp:ListItem>
<asp:ListItem Value="24">12 PM</asp:ListItem>
</asp:DropDownList> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Hours">
<HeaderTemplate>
Total
<br />
Hours
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblTotalHr" runat="server"></asp:Label>

</ItemTemplate>
</asp:TemplateField>
</Columns>

</asp:GridView>
Thank You in advance
Sep 23 '07 #1
0 1355

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
2
by: Mike P | last post by:
Is it possible to perform calculations on data in your gridview in your ASP, or do you need to do any calculations in the OnRowDataBound event? Here is what I am trying to do : ...
6
by: igotyourdotnet | last post by:
I have a dataset that is populating my gridview, but I have a data in the dataset coming out like .011 and showing in the gridView as .011%. I need to calculate that so it shows as 1.1% and not...
3
gchq
by: gchq | last post by:
Using both static data and data from some GridView cells I am attempting to calculate a result in a Template Cell - but to no avail! The value for TextBox1 is brought in on the page_load event and...
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
1
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have a series of Database tables which hold various fields and details of how they are calculated. I take these details and bind them to a Gridview with a Description of each item and a...
3
by: Mike | last post by:
On my gridview I need to a add a new row that will have totals of a previous rows. It will be something like this row1 1 2 3 4 9 10 11...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.