Customize custom field displaypattern to pass current item info to another page in MOSS 2007

Suppose we have a custom field and we want to edit it on another page, not in default edit page. Then we need to pass current item information to that page which should be able to access and edit the field.Generally, it is required because we can’t edit item in the listview.CAML is used in the display pattern.

Assume the custom edit page(editme.aspx) is deployed on main site, then first we require host address in display pattern, For this use <HttpHost /> element and after this give page name(editme.aspx).
Output: http://server/editme.aspx
Now we will pass following parameters in query string:
ID: <Column Name="ID" />
fieldName: <Property Select="Name" />
ListGUID: <List/>
<ScriptQuote NotAddingQuote="TRUE">
<PageUrl URLEncode="TRUE"/>
These information(ID,fieldName,ListGUIDand PageURL) are sufficient to edit this item. The complete code looks like:

<RenderPattern Name="DisplayPattern">
<![CDATA[<a href="javascript: void(0)"
<HttpHost />
<Column Name="ID" />
<Property Select="Name" />
<ScriptQuote NotAddingQuote="TRUE">
<PageUrl URLEncode="TRUE"/>

<Column HTMLEncode="TRUE" />

In editme.aspx page:

string pageurl = Request["pageurl"].ToString();
string fieldName = Request["fieldName "].ToString();
string lstguid = = Request["listguid"].ToString();
int itemID = Convert.ToInt32(Request["ID"]);
using (SPWeb oWebsite = new SPSite(pageurl).OpenWeb())
SPList oList = oWebsite.Lists[new Guid(lstguid)];
SPListItem oListItem = oList.GetItemById(itemID);
oListItem[fieldName] = "Sample Value";
oWebsite.AllowUnsafeUpdates = true;

On clicking custom field item in listview, editme.aspx page will be opened and value is replaced with “Sample Value”.
Hope ! it helps.

No comments:

Post a Comment