Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi everyone, i want to divide 2 field in SharePoint using visual studio c#. I have the code as shown below
SPView vw = jobDef.View["All items"];
vW.ViewFields.Add("MinSalary");
vW.ViewFields.Add("MaxSalary");
vW.ViewFields.Add("AvgSalary");
vw.InLineEdit = "TRUE";
vw.update();


SPListItem newDef;
newDef = jobDef.Items.Add();
newDef["MinSalary"] = "40000";
newDef["MaxSalary"] = "80000";
newDef["AvgSalary"] = int.Parse("MaxSalary")/ int.Parse(MinSalary); // i dont know how what to do here

anyone help me please!
Posted
Updated 2-Aug-16 1:41am

i solved it by myself thanks anyway
int avgSalary = Convert.ToInt32(newDef["MaxSalary"]) / Convert.ToInt32(newDef["MinSalary"]);
newDef["AvgSalary"] = avgSalary.ToString();
 
Share this answer
 
Hi Nderon Hiseni,

I suggest you should create calculated field in list.
You can apply formula to your field, whose result may or may not be dependent on other column in list.

My suggestion is
1. Create calculated column manually(possible with c# too) in list from advance setting of list.
2. Apply your formula
3. Add column in View


Work Done !!!!


References :
Manually[^]
By code[^]
Learn more about formula[^]

Note : Out of box is always better than customization, it minimizes bug possibility.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900