SharePoint Development Bookmark and Share   
 index > SharePoint - Development and Programming > "Edit in Datasheet View" be the default view programmatically?
 

"Edit in Datasheet View" be the default view programmatically?

Hi All,

I need to be able to set "Edit in Datasheet View" as the default view in a ListViewWebPart. Is that possible?

For example, we have a list that is being surfaced from within a listviewwebpart on a page. Now, if users want to view the list in DataSheet, one has to click "Actions" and then "Edit in Datasheet View". I was wondering if it is was possible to load this list in datasheet view by default when they load the page?

Thanks for any pointers.
diffident  Monday, June 15, 2009 7:43 PM
Hi,

You should create a new view of Datasheet type and set it as the default view. That's all.

To create a (datasheet) view from code you should use the Add method of the SPViewCollection as illustrated on the following page:
http://msdn.microsoft.com/en-us/library/ms480493.aspx
As in the example on the page (see the VB example, as C# is not the same!), you should use the SPViewType.Grid enum value for the view type.

With an existing view (for example All Items that is a standard view type) you cannot do that, or at least it requires more tricks.

Peter
  • Marked As Answer bydiffident Monday, June 15, 2009 9:49 PM
  •  
Peter Holpar  Monday, June 15, 2009 9:40 PM
Hi,

You should create a new view of Datasheet type and set it as the default view. That's all.

To create a (datasheet) view from code you should use the Add method of the SPViewCollection as illustrated on the following page:
http://msdn.microsoft.com/en-us/library/ms480493.aspx
As in the example on the page (see the VB example, as C# is not the same!), you should use the SPViewType.Grid enum value for the view type.

With an existing view (for example All Items that is a standard view type) you cannot do that, or at least it requires more tricks.

Peter
  • Marked As Answer bydiffident Monday, June 15, 2009 9:49 PM
  •  
Peter Holpar  Monday, June 15, 2009 9:40 PM
Thanks Peter, that did the trick.

I have a quick question. By default the width of the columns for the datasheet is set to certain number of pixels. Is there a wayI can reduce that?
diffident  Monday, June 15, 2009 9:49 PM

Well, that is an interesting question. I think it may be done for example using JavaScript, but I am afraid it is non-trivial. I suggest you to create a new thread for the following reasons:
- The theme is not strongly related to the title of this thread.
- The question in the title is answered, and somebody looking for problems to solve may not read your new question.

After creating the new thread you may leave a reference URL pointing to it here for the ones who come later.

Peter

Peter Holpar  Monday, June 15, 2009 10:09 PM

You can use google to search for other answers

Custom Search

More Threads

• download template from doc lib
• How to change calendar type algorithm ?
• How to add C# code block in SharePoint ASPX page.
• Custom Site Navigation Not highlighting
• Content Types with Custom List Definitions
• Slide Show Picture Before and Picture After Side By side
• refreshing page problem?
• Query document library based on the current date
• Submit List data in a frame page list
• Update the excel document in a sharepoint list.