I used this code:
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................