Link to home
Start Free TrialLog in
Avatar of dickchan
dickchan

asked on

Add button to web part in WSS3

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
ASKER CERTIFIED SOLUTION
Avatar of AlMothanaAlOmari
AlMothanaAlOmari
Flag of Jordan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AndrewSkoraro
AndrewSkoraro

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;
        }


Avatar of dickchan

ASKER

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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial