Solved

Add button to web part in WSS3

Posted on 2011-02-20
5
619 Views
Last Modified: 2012-05-11
I want to customize a web part page in WSS3 to show contact list for three offices.

When i click first buttion, the content part show contact list of office 1;
When i click button 2, it show contact list of office 2;
When i click button 3, it show contact list of office 3;

Any idea how can i do this?
I am new to sharepoint.
Thanks a lot.

list.jpg
0
Comment
Question by:dickchan
5 Comments
 
LVL 7

Accepted Solution

by:
AlMothanaAlOmari earned 167 total points
ID: 34940848
0
 
LVL 14

Assisted Solution

by:KoenVosters
KoenVosters earned 166 total points
ID: 34941078
AlMothana your post is for SharePoint 2010.

DickChan I presume I can assume you have some development knowledge. In that case this link should point you in the right direction:
http://www.c-sharpcorner.com/UploadFile/sarav82/webpartlifecycle01102008061313AM/webpartlifecycle.aspx
0
 
LVL 3

Expert Comment

by:AndrewSkoraro
ID: 34946254
Where is the contacts data stored?  If its a list then I would just filer the list results using a caml query.  

Start by adding a required column named Office to your contacts list.  Make this a choice column and add your three offices as the list of choices.

Create the webpart in VS and add the three buttons.

Here is the code to filter the list and return the results as a DataTable.  Use the DataTable to bind to a grid or iterate through the SPListItemCollection directly if you wish to write out the results yourself.  If you use a grid or other bindable control you will need to limit the results to the required fields or you will end up with a lot of unnecessary output as it contains all columns from the list.

        public static DataTable GetContactsDataTable(string office)
        {
            DataTable ret = null;

            try
            {
                SPList contactsList = SPContext.Current.Web.Lists["Contacts"];
                SPQuery query = new SPQuery();
                query.Query = string.Format("<Query><Where><Eq><FieldRef Name='Office' /><Value Type='Choice'>{0}</Value></Eq></Where></Query>", office);
                               
                SPListItemCollection contactsListItems = contactsList.GetItems(query);

                ret = contactsListItems.GetDataTable();  
            }
            catch (Exception ex)
            {
                //Handle Exception
            }

            return ret;
        }


0
 

Author Comment

by:dickchan
ID: 34948957
Contacts data is stored in a word file. Each office on file.
Any web part can load the content of the word or PDF file directly?
0
 
LVL 3

Assisted Solution

by:AndrewSkoraro
AndrewSkoraro earned 167 total points
ID: 34955203
Is it possible to change the information to something that will work as a valid data source? Excel or SharePoint list?  
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have just recently built a new SharePoint 2007 farm on a complete Windows 2008 R2 server platform and part of my standard build procedure is to implement a warm up routine, usually in the form of a script that is scheduled every morning to launch …
If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now