TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Terry
NA
148
0
Find the sum of all values of a column in ListView
Mar 23 2015 5:20 PM
In my ListView, I have InsertTemplate :
<InsertItemTemplate>
<td>
<asp:DynamicControl runat="server" DataField="PercentageOfPayment" ID="PercentageOfPaymentIns" Mode="Insert" />
</td>
</InsertItemTemplate>
In my InsertMethod, I want to iterate thru all the items of ListView & sum up the values of "PercentageOfPayment" field. If it exceeds 100, I want to warn the user. This is the code of my InsertMethod that shows various things I had tried for this :
public void paymentList_InsertItem()
{
decimal percentagetotal = 0;
if (currentProject == null)
currentProject = _db.Projects.Find(projectId);
var item = new VincitoreCRMApplication.Models.PaymentSchedule(projectId, projectName);
TryUpdateModel(item);
if (ModelState.IsValid)
{
foreach (ListViewItem lvi in paymentList.Items)
{
PaymentSchedule sc = (PaymentSchedule)lvi.DataItem;
if (sc != null)
{
System.Diagnostics.Debug.WriteLine("$$$$$$$$$ SC = " + sc.PercentageOfPayment);
}
else
System.Diagnostics.Debug.WriteLine("$$$$$$$$$ SC = null");
/*
//if (Decimal.TryParse(lvi.))
if (lvi.ItemType == ListViewItemType.DataItem)
{
System.Web.DynamicData.DynamicControl dc = paymentList.FindControl("PercentageOfPaymentIns") as System.Web.DynamicData.DynamicControl;
}
percentagetotal += p.PercentageOfPayment;*/
}
//paymentList.Items.Sum()
if ((totalPercentage + item.PercentageOfPayment) > 100)
{
System.Diagnostics.Debug.WriteLine("$$$$$$$$$ PERCENTAGE TOTAL Comes To " + percentagetotal + " .. NOT Valid > 100");
}
else
{
// Save changes here
_db.PaymentScheduleOfProject.Add(item);
_db.SaveChanges();
paymentList.EditIndex = -1;
}
}
}
I referred many sites, tried to iterate and find the sum, but couldn't achieve it. What am I missing over here, can you point out and help me solve it !!
Any help is highly appreciated.
Thanks
Reply
Answers (
0
)
Access a Control from EditItemTemplate and update a Property
how to hide and unhide the particular frame in asp.net web p