How to set the value of a look-up field?

Hi,

    I have a asp drop down box in my application page. I use a column called country from a list as a data source for the drop down box. I also have a look up field in a list, which looks up to the same country column. Now I need to set  the value selected in the drop down box to the look up field. 

  Can any one give me some idea, to achieve this?

Thanks

Gopal

October 29th, 2013 11:07am

Hi,

According to your post, my understanding is that you want to set the asp DropDownList selected value to look up field.
SharePoint provides the class SPFieldLookupValue to achieve it.

The code snippet below for your reference:

string text = DropDownList1.SelectedItem.Text;
string value = DropDownList1.SelectedItem.Value;
SPWeb spWeb = SPContext.Current.Web;
SPList splist=spWeb.Lists["TestList"];
SPListItem item = splist.Items.Add();
item["country"]=new SPFieldLookupValue(Int32.Parse(value),text);
item.Update();

Best Regards,
Denn

Free Windows Admin Tool Kit Click here and download it now
October 30th, 2013 3:38am

hi

if i understand

You hava A-list as data source amd a B-list which will use a column from A-list as lookup

Also you have another C-list which you need to use B-list as source on same column

The easiest way

on list B

create a new column -

attach a workflow to B-list , which will start when an item is adde and/or changed - and  wich will fill this new column with lookup column's value

Next in list C, use the B-list new column's value as source for your lookup column

October 30th, 2013 4:54am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics