Click here to Skip to main content
15,991,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used this code:
C#
protected void Button1_Click(object sender, EventArgs e)
        {


            using (SPSite site = new SPSite(Convert.ToString(SPContext.Current.Web.Url)))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    using (SPWeb web1 = site.OpenWeb("Sales"))
                    {

                        web.AllowUnsafeUpdates = true;
                        SPList list1 = web.Lists["AviList1"];
                        SPList list2 = web1.Lists["AviList2"];
                        if (list1 != null)
                        {


                            string fieldXML = "<field displayname="MyLookUpColumn" type="Lookup" required="FALSE" list="" list1.id="" webid="" web.id="" name="MylookUpColumn" showfield="" />";
                            list2.Fields.AddFieldAsXml(fieldXML, true, SPAddFieldOptions.AddFieldToDefaultView);

                            
                        }
                    }
                }
            }


}

AviList1 is on rootsite and has two columns: Name column which is of type single line text and Country column which of type choice.

When I run this code a column 'MyLookUpColumn' is added in AviList2 with values that I have made entries in Country column of AviLIst1.But problem is that when I make entries in AviLIst2.

What is happening, instead of saving value in MyLookUpColumn column of AviList2,it is saving #err in that column of AviList2.

Please solve my problem as soon as possible.Plz send the code.Thanks in advance.







Please read my whole problem carefully & then please reply.
Thanks a lot................
Posted
Updated 4-Nov-11 1:32am
v3
Comments
[no name] 4-Nov-11 9:36am    
This is a volunteer site, people will answer on their time, not yours, so don't ask for a solution "as soon as possible"

1 solution

See here for how to add a LookupColumn programatically http://sarangasl.blogspot.com/2009/11/add-lookup-column-to-sharepoint-list.html[^]
 
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