I have a webpart that renders random list items (from any list and list type) in a specified format. I want the items that are being displayed in the webpart to link to their ListItem detail views. However, I don't see a property on the list itself that would tell me what view is the default DETAIL view for the list (ie. blog list detail is Post.aspx). Does this come from the list definition? How would I get that information programmatically? I'm trying to avoid hard-coding any list information based on list type.
+6
A:
Have a look at SPList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url
.
I think this is what you're looking for. You'll need to append the the SPListItem.ID on the querystring so that it knows which list item to display.
using (SPWeb myWeb = GetMyWeb()) // GetMyWeb gets a reference to a SPWeb object
{
SPList myList = GetMyList(myWeb); // GetMyList gets a reference to a SPList object
SPListItem myItem = GetMyListItem(myList); // GetMyListItem gets a reference to a SPListItem object
string url = String.Format("{0}/{1}?ID={2}",
myWeb.Url,
myList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url,
myItem.ID);
}
It's also a good practice to append &Source=/url/to/current/page
to the querystring so that users will be redirected back to the page they left when they click the Cancel/Close buttons on the Edit or Display forms.
Lloyd Cotten
2008-12-03 18:54:44
That worked great! Thanks.
Ryan Eastabrook
2008-12-03 19:27:55
A:
what about situation when we have few content types on list???
robert kwapiszewski
2010-08-10 12:07:06