Hello,
Have jsut completed the code in the Try It Out on page 578 and and the hyperlink doesn't work at all.
When I place the mouse over the link the mouse changes to a vertical cursor similar to a word processor and the link becomes underlined however left clicking the hyperlink has no affect.
My Default.aspx.cs code 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;
publicpartialclassDefault : BasePage
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
switch (e.Item.ItemType)
{
caseListViewItemType.DataItem:
Button deleteButton = (Button)e.Item.FindControl("DeleteButton");
deleteButton.Visible = Roles.IsUserInRole("Managers");
break;
}
}
protectedvoid ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protectedvoid ListView1_DataBoud(object sender, EventArgs e)
{
int photoAlbumId = Convert.ToInt32(DropDownList1.SelectedValue);
using (PlanetWroxDataContext myDatabaseContext = newPlanetWroxDataContext())
{
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:
<%@PageLanguage="C#"MasterPageFile="~/MasterPages/MasterPage.master"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="Default"Title="All Photo Albums" %>
<asp:ContentID="Content1"ContentPlaceHolderID="head"runat="Server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="cpMainContent"runat="Server">
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"DataSourceID="LinqDataSource1"DataTextField="Name"DataValueField="Id">
</asp:DropDownList>
<asp:ListViewID="ListView1"runat="server"DataKeyNames="Id"DataSourceID="LinqDataSource2"onitemcreated="ListView1_ItemCreated"onselectedindexchanged="ListView1_SelectedIndexChanged">
<LayoutTemplate>
<ulclass="itemContainer">
<liid="itemPlaceholder"runat="server"/>
</ul>
<divstyle="">
<asp:DataPagerID="DataPager1"runat="server"PageSize="3">
<Fields>
<asp:NextPreviousPagerFieldButtonType="Button"ShowFirstPageButton="True"ShowLastPageButton="True"/>
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<ItemTemplate>
<li>
<asp:ImageID="Image1"runat="server"ImageUrl='<%# Eval("ImageUrl") %>'ToolTip='<%# Eval("ToolTip") %>'/>
<asp:LabelID="DescriptionLabel"runat="server"Text='<%# Eval("Description") %>'/>
<asp:ButtonID="DeleteButton"CommandName="Delete"runat="server"Text="Delete"/>
</li>
</ItemTemplate>
</asp:ListView>
<asp:LinqDataSourceID="LinqDataSource2"runat="server"ContextTypeName="PlanetWroxDataContext"TableName="Pictures"Where="PhotoAlbumId == @PhotoAlbumId"EnableDelete="True">
<WhereParameters>
<asp:ControlParameterControlID="DropDownList1"Name="PhotoAlbumId"PropertyName="SelectedValue"Type="Int32"/>
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSourceID="LinqDataSource1"runat="server"ContextTypeName="PlanetWroxDataContext"Select="new (Id, Name)"TableName="PhotoAlbums">
</asp:LinqDataSource>
<br/><br/><asp:HyperLinkID="HyperLink1"runat="server">Edit Photo ALbum</asp:HyperLink>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
My NewPhotoAlbum.aspx.cs code 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;
publicpartialclassNewPhotoAlbum : BasePage
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid LinqDataSource1_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Result;
Response.Redirect(string.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0}",
myPhotoAlbum.Id.ToString()));
}
protectedvoid LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
}
protectedvoid LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
{
PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.NewObject;
myPhotoAlbum.UserName = User.Identity.Name;
}
}
And lastly my NewPhotoAlbum.aspx code looks like this
Code:
<%@PageLanguage="C#"MasterPageFile="~/MasterPages/MasterPage.master"AutoEventWireup="true"CodeFile="NewPhotoAlbum.aspx.cs"Inherits="NewPhotoAlbum"Title="Create New Photo Album" %>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="cpMainContent"Runat="Server">
<asp:DetailsViewID="DetailsView1"runat="server"AutoGenerateRows="False"DataKeyNames="Id"DataSourceID="LinqDataSource1"DefaultMode="Insert"Height="50px"Width="125px">
<Fields>
<asp:BoundFieldDataField="Id"HeaderText="Id"InsertVisible="False"ReadOnly="True"SortExpression="Id"/>
<asp:BoundFieldDataField="Name"HeaderText="Name"SortExpression="Name"/>
<asp:CommandFieldShowInsertButton="True"/>
</Fields>
</asp:DetailsView>
<asp:LinqDataSourceID="LinqDataSource1"runat="server"ContextTypeName="PlanetWroxDataContext"EnableInsert="True"oninserted="LinqDataSource1_Inserted"TableName="PhotoAlbums"onselecting="LinqDataSource1_Selecting">
</asp:LinqDataSource>
</asp:Content>
The Default.aspx page picks up the name of the new albums that I type but it doesn't let me add content to them.
Any help would be most appreciated.
Thanks
Tomche