Thread: Wrox Blog
View Single Post
  #6 (permalink)  
Old May 7th, 2007, 03:41 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

If it works, than it's correct, isn't it? ;)

But no, I don't think this is correct.

Few things:

1. e.Item.FindControl("EditingId") returns a Control, not a Boolean indicating whether it can be found or not. So, you'll need to do something else with it to make this code more useful.

2. Membership.GetUser().ProviderUserKey.ToString() isn't doing anything. You grab the User, get its ID, convert the Guid to a string and that's it. You're not really using it anywhere.

3. You're not really hiding the Edit link.

I think I put you on the wrong track by saying you need to ItemCommand. It's ItemDataBound that you want. The following (untested) code should probably work:
Code:
Protected Sub dlBlogEntries_ItemDataBound(ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) _
    Handles dlBlogEntries.ItemDataBound
  Dim myDataRowView As DataRowView = CType(e.Item.DataItem, DataRowView)
  Dim userId As Guid = CType(Membership.GetUser().ProviderUserKey, Guid)
  Dim posterId As Guid = CType(myDataRowView("PostedBy"), Guid)
  Dim lnkEdit As LinkButton = CType(e.Item.FindControl("lnkEdit"), LinkButton)
  If userId.Equals(userId) Then
    lnkEdit.Visible = False
  End If
End Sub
You also need to remove the Visible='<%#CanEdit()%>' from the lnkEdit control.

This code also assumes you have a column called PostedBy which holds the Guid of the user that posted the Blog entry.

I haven't tested or run this code, so you may need to tweak it a little to get it to work.

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.