1

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.

3 Answers 3

2
  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.

0

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); 
} 
 } 
 } 
3
  • 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 Oct 9, 2012 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, 2012 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. Oct 10, 2012 at 13:25
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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