View Single Post
  #3 (permalink)  
Old August 8th, 2009, 02:31 AM
tomche tomche is offline
Authorized User
Points: 297, Level: 5
Points: 297, Level: 5 Points: 297, Level: 5 Points: 297, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,
Sorry it slipped my mind and I didn't realiese until i had already posted.

My Detail.aspx.cs from the photoalbums folder looks like this

Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
switch (e.Item.ItemType)
{
case ListViewItemType.DataItem:
Button deleteButton = (Button)e.Item.FindControl("DeleteButton");
deleteButton.Visible = Roles.IsUserInRole("Managers");
break;
}
}
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void ListView1_DataBoud(object sender, EventArgs e)
{
int photoAlbumId = Convert.ToInt32(DropDownList1.SelectedValue);
using (PlanetWroxDataContext myDatabaseContext = new PlanetWroxDataContext())
{
string photoAlbumOwner = (from p in myDatabaseContext.PhotoAlbums
where p.Id == photoAlbumId
select p.UserName).Single();
if (User.Identity.IsAuthenticated &&
(User.Identity.Name == photoAlbumOwner || User.IsInRole("Managers")))
{
HyperLink1.Visible = true;
HyperLink1.NavigateUrl = "~/ManagePhotoAlbum.aspx?PhotoAlbumId=" +
photoAlbumId.ToString();
}
else
{
HyperLink1.Visible = false;
}
}
}
}
My default.aspx code looks like this

Code:
<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" Title="All Photo Albums" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="LinqDataSource1" DataTextField="Name" DataValueField="Id">
</asp:DropDownList>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" 
DataSourceID="LinqDataSource2" onitemcreated="ListView1_ItemCreated" 
onselectedindexchanged="ListView1_SelectedIndexChanged">
<LayoutTemplate>
<ul class="itemContainer">
<li id="itemPlaceholder" runat="server" />
</ul>
<div style="">
<asp:DataPager ID="DataPager1" runat="server" PageSize="3">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<ItemTemplate>
<li>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' ToolTip='<%# Eval("ToolTip") %>' />
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
<asp:Button ID="DeleteButton" CommandName="Delete" runat="server" Text="Delete" />
</li>
</ItemTemplate>
</asp:ListView>
<asp:LinqDataSource ID="LinqDataSource2" runat="server" 
ContextTypeName="PlanetWroxDataContext" TableName="Pictures" 
Where="PhotoAlbumId == @PhotoAlbumId" EnableDelete="True">
<WhereParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="PhotoAlbumId" PropertyName="SelectedValue" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="PlanetWroxDataContext" Select="new (Id, Name)" TableName="PhotoAlbums">
</asp:LinqDataSource>
<br /><br /><asp:HyperLink ID="HyperLink1" runat="server">Edit Photo ALbum</asp:HyperLink>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
My photoalbum.aspx.cs file looks like this
Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class NewPhotoAlbum : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void LinqDataSource1_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Result;
Response.Redirect(string.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0}",
myPhotoAlbum.Id.ToString()));
}
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
}
protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
{
PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.NewObject;
myPhotoAlbum.UserName = User.Identity.Name;
}
}
My newphotoalbumaspx file looks like this

Code:
%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="NewPhotoAlbum.aspx.cs" Inherits="NewPhotoAlbum" Title="Create New Photo Album" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="LinqDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
ContextTypeName="PlanetWroxDataContext" EnableInsert="True" 
oninserted="LinqDataSource1_Inserted" TableName="PhotoAlbums" 
onselecting="LinqDataSource1_Selecting">
</asp:LinqDataSource>
</asp:Content>
Remove text formatting button applied

Cheers

Thomas
Reply With Quote