Wednesday, June 10, 2009

Using MultiLookupField & Richtextfield in a webpart

Earlier I tried to use MultiLookUpField in my webpart but got stuck with one issue. Later on I was able to correct it. To use multilookup in your webpart you will need to make sure that ID is either a HardCoded value or the check for the Field.Title whether it doesnt any blank space in it.
SPList CurrentList = myDestinationListWithReferrerLookupField;
multiLookup.ID = "multiLookupID";
multiLookup.ListId = CurrentList.ID;
multiLookup.FieldName = Field.Title;
multiLookup.ControlMode = SPControlMode.New;
multiLookup.ItemId = CurrentList.Items[0].ID;
this.Controls.Add(multiLookup);

Now to retrieve the value selected by user is quite straight forward, just do
multiLookup.Value, which will return an object to be assigned to MultiLookup field
itm["MyLookUpReferrer"] = multiLookup.Value;

One thing I was quite amazed to see was that while creating multilookupfield control there was no need to assign anywhere the SourceLookupField, I guess that below
multiLookup.ItemId = CurrentList.Items[0].ID
line does the job for us.

Now adding RichTextField to a webpart is straightforward , just need to remember to give ID value of the List which contains a column with "Multiple lines of text", The "Field" below refers to such column.
txtRichDiscript.ID = "txtRichDiscript";
txtRichDiscript.ListId = CurrentList.ID;
txtRichDiscript.FieldName = Field.Title;
txtRichDiscript.ControlMode = SPControlMode.New;
this.Controls.Add(txtRichDiscript);

No comments:

Post a Comment