Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want update with some changes one list from another. The secand list should have details of first list.

First list has got elements:

                Contract | Worker | Day Start   | Day Stop   | Percent
                --------------------------------------------------------
 Example        Con1     | Paul   | 2012-10-12  | 2012-10-15 | 1/8

Secound List should have

                Contract   |   Worker   |   Day      |   Percent
                ------------------------------------------------
Should Have     Con 1      |    Paul    | 2012-10-12 |    1/8
                Con 1      |    Paul    | 2012-10-13 |    1/8
                Con 1      |    Paul    | 2012-10-14 |    1/8
                Con 1      |    Paul    | 2012-10-15 |    1/8

So In this example I want get from one list and one data record, 4 record with escribe of days. Please help me

I have vriten a Code, but it always copy elements, and only I want to update when anothere element is added:

    protected void Button1_Click(object sender, EventArgs e)
    {




        SPWeb witryna = SPContext.Current.Web;
        SPListItemCollection czasPracyWpisy = witryna.Lists["DR2013 Czas Pracy Wpisy"].Items;
        SPListItemCollection czasPracySzczegoly= witryna.Lists["DR2013 Czas Pracy Szczegóły"].Items;



        int index;
        string hfzm1, hfzm2;


        foreach (SPListItem oCzasPracyKolejnyWpis in czasPracyWpisy)
        {
            foreach(SPListItem oCzasPracyKolejnySzczegoly in czasPracySzczegoly){

            Label1.Text = oCzasPracyKolejnyWpis["Numer Kontraktu/Oferty/Szansy"].ToString();
            Label2.Text = oCzasPracyKolejnyWpis["Pracownik"].ToString();
            Label3.Text = oCzasPracyKolejnyWpis["Dzień Start"].ToString();
            Label4.Text = oCzasPracyKolejnyWpis["Dzień Stop"].ToString();
            index = oCzasPracyKolejnyWpis["Procent"].ToString().IndexOf("#");
            Label5.Text = oCzasPracyKolejnyWpis["Procent"].ToString().Substring(index + 1);

            // Dodawanie poszczególnych elementów

               hfzm1 = oCzasPracyKolejnySzczegoly["Numer Kontraktu/Oferty/Szansy"].ToString();
               HFzm1.Value=hfzm1;
               hfzm2 = oCzasPracyKolejnyWpis["Numer Kontraktu/Oferty/Szansy"].ToString();
                HFzm2.Value=hfzm2;


            }

            if (
(HFzm2.Value != HFzm1.Value && HFzm1.Value ==HFzm2.Value || HFzm1.Value=="" || HFzm2.Value=="" )
                )
            {
                SPListItem item = czasPracySzczegoly.Add();



                item["Numer Kontraktu/Oferty/Szansy"] = oCzasPracyKolejnyWpis["Numer Kontraktu/Oferty/Szansy"].ToString();
                item["Pracownik"] = oCzasPracyKolejnyWpis["Pracownik"].ToString();
                item["Dzień"] = oCzasPracyKolejnyWpis["Dzień Start"].ToString();
                index = oCzasPracyKolejnyWpis["Procent"].ToString().IndexOf("#");
                item["Procent"] = oCzasPracyKolejnyWpis["Procent"].ToString().Substring(index + 1);
                item.Update();
            }
            else
            {
                Label6.Text = "Mamy do czynienia ze zduplikowanymi wartościami";
            }
        }

    }

}

}

share|improve this question
add comment

2 Answers

So In this example I want get from one list and one data record, 4 record with escribe of days.

Dint get this line, you requirement is not clear here, you said you want to add item, but here you are showing values in some label also, so what sort of application is this? and you used HFzm1 & HFzm2, what are these?

I want to update when anothere element is added:

If that's the case you need an event handler on the first list, it's pretty simple job. This may help you to start with.

You need to handle 'ItemAdded' event of list. Kindly ask for any help with event handler code.

share|improve this answer
    
Thank's for replay. First of all I want add element. { - The label's are because i want to see what I'm adding to the list's. The Label's are here for teasting. I want to add element, to the secound("DR2013 Czas Pracy Wpisy") list, only when it's added to first("DR2013 Czas Pracy Wpisy"), but without a duplicate. } If i Can geret i want to take a date from Start Date to End Date, and add when it's example Start Date is 2012-10-12 and end date is 2012-10-15, so i mast add to sexound description list 4 elements. Please help me –  Grzegorz Z Oct 12 '12 at 12:09
    
Have you tried event receiver? as mentioned in my answer, please try it –  Diptarag Oct 13 '12 at 19:18
add comment

Thank's for replay :)

But how to add the secoundary list to the propeties, and write a Handler of Event Handler.

First of all I want add element. {

  • The label's are because i want to see what I'm adding to the list's. The Label's are here for teasting.

    I want to add element, to the secound("DR2013 Czas Pracy Wpisy") list, only when it's added to first("DR2013 Czas Pracy Wpisy"), but without a duplicate.

}

If i Can geret i want to take a date from Start Date to End Date, and add when it's example Start Date is 2012-10-12 and end date is 2012-10-15, so i mast add to sexound description list 4 elements.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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