Cizi

From the desktop of SharePoint girl

January 2009 - Posts

Delete Item from Data View

A few days ago I had to give my users access to delete items directly from the data view. I have noticed that the designer's default delete option is missing the validation question "Are you sure you want to delete this item?". This post will explain how to add the delete item link with the prompted question.

In Addition I didn't like the "Insert Item" and "Edit Item" links and I changed them as well – but this is issue for another post.

Adding delete link

After you add a data view to your page choose Data View Properties from Common Data View Tasks menu. In the Data View Properties window, under Editing tab click Show delete item links (I also checked the other options and will talk about them in another post).

DataProperties

You can see that the links are added to the data view:

DataView2

If you click on the Delete link – the item will be deleted without asking you if you are sure about it.

Changing the link

look for this line in your page:

<a href="BLOCKED SCRIPT {ddwrt:GenFireServerEvent(concat('__cancel;__delete={',$KeyField,'=',$KeyValue,'};__commit'))}">delete</a>

and replace it with (or just add the green text):

<a href="BLOCKED SCRIPT {ddwrt:GenFireServerEvent(concat('__cancel;__delete={',$KeyField,'=',$KeyValue,'};__commit'))}" onclick="return DeleteItemConfirmation();"> delete</a>

The function DeleteItemConfirmation is a function from core.js that ask the user if he's sure about deleting this item.

AreYouSure1

It is important to say that there is no permission validation in this way – every user can see the delete link. However , if the user will click on the link without suitable permissions he will get the "Access Denied" page.   

In the next posts i'll talk about the edit and insert option.

I hope this post was useful.

Inbar

Filtering Data Views with ASP Controls

In the previous post I talked about filtering data views with URL parameters. In this post I will deal with filtering the data with ASP.Net controls.

Tip – You can’t insert the control when you point on a web part zone; You can add <br> tag under a web part zone and add the control there.

Here are the steps:

Right-click on the list/library that will supply the values for the control in the Data source library panel. Chose the second option “Insert source data control”. If your prompted to turn on “Visual Aid” click yes. SPDataSource was added to your page.

InsertDataSourceControl

DataSourceInThePafe 

In the top menu chose Insert > ASP.NET controls > Drop down list, an ASP control was added to your page. Click on the small arrow next to the control, from the Common DropDownList Task menu click Chose Data Source… and then chose spdatasource1, fill in the other fields as shown in the example(In this example I would like to filter according to the title). Click OK and Check Enable Auto Post Back.

ASPControlWIthDataSource

ChooseDataSourceWithDataSou

Now add your data view (1). Click on the small arrow of the data view, from the Common Data View Task menu chose Filter (2). In the Field Name choose the field that you want to filter by (Document type for this example), in the Value field chose Create new parameter (3).

FilterCareria

In the Data view Parameters window, under Parameters source filed chose Control. In Control ID filed chose you control ID (probably DropDownList1),You can add default value. Click Ok and Ok.

Parmeters

5. Save you page and view it in the browser.

DropDownPage

DropDownPage2

– if you reattach you page to layout the control will be lost. The reason is that we broke the connection to the layout when we placed the asp control outside the web part zone.

Filtering Data Views With Query String

A few days ago I needed to filter web part with values from a web part that is located in another page. Usually I would have done it with Query String (URL) Filter web part. Unfortunately, my client didn’t have enterprise edition and I had to think of another way to implement this. The answer was (of course) Data view! lets see how it can be done.

Create 2 pages - the first will display the web part with the values, the second will be filter by these values.

Go to your first page and create data view with the values to filter by (in this example documents types).

NewDataView

Now, make the values clickable: Click on the name of the field and choose Hyperlink in Format as… field.

ConvertToHyperlink

In the address filed chose the destination page (the second page you created – number 1 in the following picture) and add the parameters in this structure: ParmName={@Filed} in this example DocType={@Title}  (Number 2 in the following example).

For every parameter you would like to pass in the URL you will need this structure; in order to add more parameters use &. For example: DocType={@Title}&ID={@ID}. Click ok.

Hyperlonk

 

  • The display name was change – use only {@Title} (or any other filed you need) (Number 3 in the above example).
  • The value are now Hyperlinks (next picture).

AllItems-Arelink

Reattach the page, check it in and close it.

Detach the second page from its layout and insert you data view. This data view should be the one that will be filter according to the values in the first page.

Click on the small arrow next to the data view and chose filter. Under the field name chose the field that will be filter (in my example – document type); Under value chose Create new parameter…

FilterCartria

Data view parameters window will appear. Under Parameters source chose Query String, under Query String Variable enter the parameter you used in the first page as hyperlink (as shown in the following picture). In my example: DocType. You can also add default value. Click OK and then Ok.

Parmeters

You can see that now, there are no items in the web part. For your connivance you can check Show with sample data checkbox (in the Common data view tasks menu).

Reattach the page, check it in and close it.

Now, let’s go to the first page we created. Click on one of the filter values and see the result…

firstPage

(I clicked on Detailed Design and here is the result…)

secoundPage

In this example I chose to display “document type” in the data view in second page (in addition to the first page). When you’re using data view it is not necessary; But when you are using the browser web parts you have to display these fields in order to filter the web parts. 

  I find this way much easier to work with (rather than URL Filter web part) because when your working with the filter web part – every time you will edit the page in the SPD the connection will be remove automatically (unless you’re working in code mode all the time).

 

Hope this post was helpful.

Inbar.