If you have ever tried to create a custom display form or try to redirect to a custom page from DispForm.aspx you will get an error “Item not found at ….. . It may have moved or renamed by the user.”
It’s because sharepoint by default uses the Querystring parameter with the name “ID”. And when we try to use the same name for our custom page it throws an exception.
So we have to use some other parameter name instead of “ID”. This will be easy if your custom page contains your custom webpart. But if your page contains a custom list webpart provided by default which you add through SharePoint designer, just changing the querystring parameter name will not do. Lets see how to do it.
Say I have two views for a list and when i click an item from View1 it should take me to CustDispForm1 and for View2 it should be CustDispForm2.
1) I have created two webpart pages(CustDispForm1, CustDispForm2) and through the designer I added the Custom List Form of the list.
2) I created a webpart deployed on DispForm.aspx which will redirect to one of the custom page based on the page/view from which its coming. ( The view from which its coming can be found from the Querystring parameter “Source“).
3) Now in the webpart i should add a code like
Note that here i have given the ID of the item in querystring but the parameter name is changed to “DisplayItemID”.
4) Of course the above code will redirect to my custom pages based on the different views. But if you remember our custom page contains a “Custom List Form webpart” which will display item based on the QueryString parameter with name “ID”.
5) Here comes the trick and we have to change this parameter name “ID” to our parameter name “DisplayItemID”.
6) Open the Custom display form (CustDispForm1.aspx) and find the tags
<ParameterBinding Name=”ListItemId” Location=”QueryString(ID)” DefaultValue=”0″/>
7) Replace “ID” with “DisplayItemID” in this code.
8 ) That’s all and now check your page in the browser.