Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to have an interface where in there are few buttons and on click of every button i want to display a Custom List View.

Firstly is it possible to programmatically display a list view in a custom webpart and allow users to add or edit items?

Suppose i have four buttons in my custom webpart,

say A1, A2, A3, A4 and a asp panel

Now on click of A1 Button i want to display a custom List View of List A in a asp panel. Accordingly on click of A2, A3, A4 i want to display custom List View for List B, C and D respectively.

Can i achieve this functionality if i have a panel and can be updated programatically as per the button clicked.

My aim is to design interface to add edit list items in some of the Master Lists i have in my project using custom webpart.

Any guidance or suggestion would be great.

Thanking You in advance.

share|improve this question

3 Answers 3

up vote 1 down vote accepted
  XsltListViewWebPart lvwp = new XsltListViewWebPart();
  lvwp.ListDisplayName = "{Display Name of the List}";
  lvwp.ViewFlags = SPViewFlags.Calendar;//Can choose different, i have choosen Calendar
  lvwp.ViewId = 1; //View ID.
  this.Controls.Add(lvwp);

This piece of code work fine.It displays a list view allowing users to add edit delete items.

share|improve this answer

SPView has a RenderAsHtml function. So you could use web.Lists["listname"].Views["viewname"].RenderAsHtml(). More info can be found on http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spview.renderashtml.aspx

share|improve this answer

I don't think that would be hard at all. Take a look at this sample code to create a list within SharePoint. You would create the page just like any other ASPX page and then you would use the SharePoint server side OM to perform your queries on the respective lists. take a look at this custom grid it should get you going.

http://lsharepoint.com/2012/04/29/adding-gridview-to-sharepoint-2010-list-forms/

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Web; 
    using System.Web.UI; 
     using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Microsoft.SharePoint; 
     using Microsoft.SharePoint.WebControls; 
       using System.Data; 

   namespace ReadListDataWebPart 
  { 
 public class CustomListDataWebPart : WebPart 
 { 
protected override void CreateChildControls() 
{ 
  SPWeb web = SPControl.GetContextWeb(Context); 
  GridView gview = new GridView();DataTable dt = new DataTable(); 
  DataRow dr; 
  DataColumn dc; 

  foreach (SPList list in web.Lists) 
  { 
    if (list.Title == "Projects") 
    { 
      if (list.ItemCount > 0) 
      { 
        dc = new DataColumn("Project",Type.GetType("System.String")); 
        dt.Columns.Add(dc); 

        dc = new DataColumn("Client", Type.GetType("System.String")); 
        dt.Columns.Add(dc); 

        foreach (SPListItem item in list.Items) 
        { 
          dr = dt.NewRow(); 
          dr["Project"] = item["Project"];dr["Client"] = item["Client"]; 
          dt.Rows.Add(dr); 
        } 
      } 
      gview.DataSource = dt; 
      gview.DataBind(); 
    } 
  } 
  Controls.Add(gview); 
} 
 } 
 } 
share|improve this answer
    
This one is cycling through the list but you can reference here to see how to perform other actions. msdn.microsoft.com/en-us/library/ee537564.aspx –  Joseph D Surgeon Oct 9 '12 at 13:22
    
Thanks, but I do not want to use gridview, instead i want to use the existing functionality of sharepoint to add, edit, delete list item. So i just want the Sharepoint list vied to be displayed in a custom webpart. –  Ishan Oct 10 '12 at 5:16
    
Ok make a tab controlled page using each page having a webpartzone and then you can add the respective sharepoint grids or forms. I can show you how to make a tab control similar to your request. Other than that you can use the SPGridView which doesn't require such code but you will have to code your buttons. –  Joseph D Surgeon Oct 10 '12 at 13:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.