Hello how to add to the value by bottom click not from the Adding Item. Only from code:

          protected void Button2_Click(object sender, EventArgs e)
                using (SPWeb witryna = SPContext.Current.Web)
                    SPListItemCollection listItems = witryna.Lists["Szczegoly"].Items;

                    SPListItem item = listItems.Add();
                    item["Kontrakt"] = TextBox1.Text;
                    item["Pracownik"] = TextBox2.Text;
                    item["Dzien"] = TextBox3.Text;
                    item["Procenty"] = TextBox4.Text;

Here is My code. How can I choise and add a Value to item["Procenty"] = TextBox4.Text; When I debug it show me that Value is no-writable.


You have to create a SPFieldLookupValue object,

SPFieldLookupValue splkup=new SPFieldLookupValue(TextBox4.Text);
item["Procenty"] = splkup;
|improve this answer|||||
  • But now it's tells me that the value is out of range. – Grzegorz Z Oct 29 '12 at 12:02
  • If I put this SPFieldLookupValue splkup = new SPFieldLookupValue(5, "5/8"); it show me 3/8 and adding – Grzegorz Z Oct 29 '12 at 12:10
  • It's a good way, but something i Schould get value – Grzegorz Z Oct 29 '12 at 13:27

What's the internal name of this field? Is it custom?

Assuming that item["Procenty"] is the same as item["PercentComplete"] you could set it with something like this (Note that TextBox.Text returns a string)

//Set item to 10% completet
item["PercentComplete"] = .10;
|improve this answer|||||
  • But the percent, are in "1/8", "2/8" .... "8/8" values – Grzegorz Z Oct 29 '12 at 11:41
  • Sorry I don't understand what you mean. You want to read the value from a TextBox which only allows "1/8" steps? Can't you just calculate the new value like 1/8=1:8=0.125 which would be 12.5%. – Aljoscha Husp Oct 29 '12 at 11:48
  • Now in percent, only in String Values – Grzegorz Z Oct 29 '12 at 12:11
  • You only have the strings 1/8, 2/8,... 8/8? Why don't you just display them that way then? Could you explain what excactly you're trying to do? Maybe in another questions, because the original question was just why you couldn't write to item["Procenty"]. – Aljoscha Husp Oct 29 '12 at 13:06
  • I want to add by boton Click Values element by element. – Grzegorz Z Oct 29 '12 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.