How to copy all *.msi files from specific subfolders with PowerShell

If you have a Microsoft Visual Studio 2010 solution, which contains setup projects and you want to copy all msi packages from the “Release” folders to one folder you can use the following script:

 

$SourceFolder = "C:\Source"
$DestinationFolder = "C:\Destination"

"Copy *.msi packages from [Release] subfolders in $SourceFolder to the $DestinationFolder"
if(Test-Path $SourceFolder )
{
    foreach ($item in Get-ChildItem "$SourceFolder" -filter "*.msi" -recurse)
    {
        if ($item.FullName -like "*Release*" )
        {
            Copy-Item $item.FullName -Destination "$DestinationFolder"
        }
    }
}

LLBLGen Pro exception: The multi-part identifier "MyDatabase.dbo.User.Name" could not be bound

If you get an exception like:

System.Web.HttpUnhandledException (0x80004005): Exception of type ‘System.Web.HttpUnhandledException’ was thrown. —> SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: The multi-part identifier "MyDatabase.dbo.User.Name" could not be bound..

make sure you use corresponding EntityFactory and Fields:

 

EntityCollection items = new EntityCollection(new UserEntityFactory()); PredicateExpression filter = new PredicateExpression(Userields.Name == username); IRelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.PredicateExpression.AddWithAnd(filter); using (var adapter = ConnectionHelper.GetAdapter(Source.LocatiePlatform, _logger)) {     adapter.FetchEntityCollection(items, bucket);     adapter.CloseConnection(); }

 

 

In the code above if you change the UserEntityFactory to an other “table factory” like PersonEntityFactory, you will get the 0x80004005 exception.

Button click event causes a RequiredFieldValidator to fire in an ASP .NET DetailsView

If you use a linkbutton and a RequiredFieldValidator in an ASP .NET DetailsView template column. The linkbutton click event causes the RequiredFieldValidator to fire. If you don’t want the RequiredFieldValidator to fire when you push the linkbutton, set the CausesValidation property to false.

CausesValidation="false"

Update a many to many relationship with LLBLGen Pro and a ASP .NET DetailsView

If you have a database model like:

image

and you want to edit a CustomerEntity with LLGLGen Pro, before you save the CustomerEntity, you should delete all records in the table CustomerPermission.

 

 

Update a Customer

The code is from a ASP .NET Webpage that uses a DetailsView to edit a Customer. It uses a CheckBoxList in the DetailsView to add and delete references between the table Customer and the table Permission.

public void Update_Click(object sender, DetailsViewUpdateEventArgs e) { // Get the current CustomerId from the current URL string customerIdInQueryString = Request.QueryString["CustomerId"]; if (!string.IsNullOrEmpty(customerIdInQueryString)) { // Only save or create a customer when a CustomerId is supplied in the URL int customerId = 0; if (int.TryParse(customerIdInQueryString, out customerId)) { CustomerEntity customer = new CustomerEntity(); // If customerId == -1 create a new customer, else edit an existing customer if (customerId == -1) { customer.IsNew = true; } else { customer.IsNew = false; } // Set customer properties customer.Id = customerId; customer .Name = e.NewValues["Name"] == null ? null : e.NewValues["Naam"].ToString();

// Foreach item in the CheckBoxList that is selected create a reference from Customer to Permission CheckBoxList cbl = (CheckBoxList)this.customerDetailsView.FindControl("PermissionCheckBoxList"); customer.CustomerPermission.Clear(); foreach (ListItem li in cbl.Items) { if (li.Selected) { CustomerPermissionEntity spe = new CustomerPermissionEntity() { CustomerId = customer.Id, PermissionId = int.Parse(li.Value) }; customer.CustomerPermission.Add(spe); } } this.UpdateCustomer(customer); // Go back to overview page (containing a RadGrid) Response.Redirect("CustomerOverview.aspx"); } } }

private void UpdateCustomer(Customerntity customer)
{
using (var adapter = new DataAccessAdapter(ConfigurationManager.ConnectionStrings["Main.ConnectionString"].ConnectionString))
{
// Delete entries in table CustomerPermission
RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(CustomerPermissionFields.CustomerId == customer.Id);
adapter.DeleteEntitiesDirectly(typeof(CustomePermissionEntity), bucket);
// Save Customer
adapter.SaveEntity(customer, true, true);
adapter.CloseConnection();
}
}

Showing the feed xml instead of the feed content in IE

If you automatically want to show the feed xml instead of the feed content in IE, when viewing a RSS feed.

Disable the “Turn on feed reading view” setting.

Tools > Internet Options > Content > Settings > uncheck “Turn on feed reading view”

(after changing the setting, I had to restart IE)

 

For developing ODATA services, this can be handy.

 

image

 

Showing the feed: https://www.roelvanlisdonk.nl/?feed=rss2 will result in:

 

<?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">

<channel>

<title>Knowledgebase</title>

<atom:link href="https://www.roelvanlisdonk.nl/?feed=rss2" rel="self" type="application/rss+xml" />

<link>https://www.roelvanlisdonk.nl</link>

<description>Blog on Microsoft SharePoint, C#, BI and PowerPivot</description>

<lastBuildDate>Thu, 24 Jun 2010 09:03:21 +0000</lastBuildDate>

<language>en</language>

<sy:updatePeriod>hourly</sy:updatePeriod>

<sy:updateFrequency>1</sy:updateFrequency>

<generator>http://wordpress.org/?v=3.0</generator>

<item>

<title>Showing and styling items in an ASP .NET 4.0 CheckBoxList using CSS and EF4.0</title>

<link>https://www.roelvanlisdonk.nl/?p=1557</link>

<comments>https://www.roelvanlisdonk.nl/?p=1557#comments</comments>

<pubDate>Thu, 24 Jun 2010 09:01:02 +0000</pubDate>

<dc:creator>Roel van Lisdonk</dc:creator>

<category>

<![CDATA

 

Normally you would see:

image

Showing, Styling and DataBind items in an ASP .NET 4.0 CheckBoxList using CSS and EF4.0

I wanted to show records in the ProductCategory table of the SQL Server AdventureWorks database in a ASP .NET 4.0 by using a CheckBoxList, without writing any code.

Result

image

 

CheckedListBox.aspx

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="CheckedListBox.aspx.cs" Inherits="Rvl.Demo.AspNet4.EF.WebApplication.Pages.CheckedListBox" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="../Styles/CheckedListBox.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
CheckedListBox page
</h2>
<asp:CheckBoxList 
ID="PcCheckBoxList" 
runat="server"
DataSourceID="PcDataSource"
DataTextField="Name"
DataValueField="ProductCategoryID"
ondatabound="PcCheckBoxList_DataBound"> </
asp:CheckBoxList> <asp:EntityDataSource ID="PcDataSource" runat="server" EnableDelete="true" EnableInsert="true" EnableUpdate="true" ConnectionString="name=AdventureWorksEntities" DefaultContainerName="AdventureWorksEntities" EntitySetName="ProductCategory" > </asp:EntityDataSource> </asp:Content>

 

CheckedListBox.css

div.main h2
{
margin-bottom: 10px;
}
div.main label
{
padding-left: 30px;
}

You can style the labels of the checkboxes with  CSS, because they are rendered as <input type=”checkbox” … /><label for=”…”></label> in html, like:

 

<table id="MainContent_PcCheckBoxList">

<tr>

<td><input id="MainContent_PcCheckBoxList_0" type="checkbox" name="ctl00$MainContent$PcCheckBoxList$0" value="1" /><label for="MainContent_PcCheckBoxList_0">Bikes</label></td>

</tr><tr>

<td><input id="MainContent_PcCheckBoxList_1" type="checkbox" name="ctl00$MainContent$PcCheckBoxList$1" value="2" /><label for="MainContent_PcCheckBoxList_1">Components</label></td>

</tr><tr>

<td><input id="MainContent_PcCheckBoxList_2" type="checkbox" name="ctl00$MainContent$PcCheckBoxList$2" value="3" /><label for="MainContent_PcCheckBoxList_2">Clothing</label></td>

</tr><tr>

<td><input id="MainContent_PcCheckBoxList_3" type="checkbox" name="ctl00$MainContent$PcCheckBoxList$3" value="4" /><label for="MainContent_PcCheckBoxList_3">Accessories</label></td>

</tr>

</table>

 

DataBind to Selected property

You can’t declaratively bind to the “Selected” property of you CheckBoxList items.

So if you want to check some checkboxes in the CheckBoxList, you should do that in the DataBound event of the CheckBoxList control. This event will fire after the control is databound, so it is filled with items.

protected void PcCheckBoxList_DataBound(object sender, EventArgs e)
{
// Check the first and last item
this.PcCheckBoxList.Items[0].Selected = true;
this.PcCheckBoxList.Items[3].Selected = true;
// To check them all, use:
//foreach (ListItem li in this.PcCheckBoxList.Items)
//{
//    li.Selected = true;
//}
}

 

 

Solution Explorer (Project Structure)

image

 

Steps

  1. Create a new ASP .NET 4.0 WebApplication in VS2010
  2. Add a ADO .NET Entity Data Model (connected to the SQL Server 2008 R2 AdventureWorks database)
  3. Add the ProductCategory table to you’re ADO .NET Entity Data Model
  4. Add a Web Form (CheckedListBox.aspx)
  5. Add a Style Sheet (CheckedListBox.css)
  6. Set CheckedListBox.aspx as startup page
  7. Run the project

How to get the primary key value in DeleteCommand event of a RadGrid

First of all you should set the MasterTableView.DataKeyNames property of the RadGrid to the primary key columns:
<MasterTableView DataKeyNames="Id">

<telerik:RadGrid ID="customerOverviewRadGrid" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="customersDS" EnableLinqExpressions="false" runat="server" ondeletecommand="customerOverviewRadGrid_DeleteCommand" > <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> <MasterTableView DataKeyNames="Id"> <Columns> . . . </Columns> </MasterTableView> </telerik:RadGrid>

Then in you’re DeleteCommand you can get you’re primary key value:

protected void customerOverviewRadGrid_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
int id = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"];
// run code to delete customer in the database . . . 
}

Making the switch: VMWare Workstation 7 to Hyper-V server for performance reasons (PowerPivot on SharePoint 2010)

 

History

Back in 2002 I was working with a company which produced a CAD application written in VB6. The product was released in several languages. For each language we had a Microsoft Windows NT 4 workstation with the corresponding language package. I quickly realized that managing these workstations was difficult. So I started to look at virtualization, but it was not until 2003 with new hardware and an other company when I decided to take a look at VMware Workstation version 4.0. This was great I could run all Microsoft Windows languages and different versions on 1 system! Then in 2004 Microsoft released Microsoft Virtual Server 2005 I took a look at the product but soon realized that it could not compete with VMware Workstation and I kept on using VMware Workstation. This worked great for me, except for 2 things:

  1. Performance, if I installed a Windows operating system on a workstation en booted from it, it was much, much faster then when I used a Virtual Machine containing the same windows operation system on that same workstation.
  2. Snapshot – Backup host, if I installed a program or driver on the host and that corrupted the host, there was no out of the box recovery (yes there where al kinds of products that can do that, but not windows out of the box) possibility. One trick I used was to install an windows host OS and then only installed VMware Workstation on it. I would only use the VMware virtual machines and only used the host OS to take snapshots and backups of my virtual machines.

VMware Workstation 7 (paid product)

Part 2 worked fine for me, but then I shifted from being a C# developer to a self-service BI specialist and Microsoft introduced PowerPivot and SharePoint 2010. In late 2009 I started to work with PowerPivot (Gemini at the time) and SharePoint 2010, so I create a VMware 7 development virtual machine with Microsoft Windows 2008 R2, Microsoft SQL Server 2008 R2, Microsoft SharePoint 2010 and Microsoft Office 2010 on a 3 year old dell laptop with 4 GB memory. Well that really did not perform at all. I bought a 80 GB Intel Postville G2 M-25 SSD, but the VMware Workstation virtual machine would not perform well and I was waiting on the system all of the time. Then one time I installed Microsoft Windows 2008 R2 as host OS with Microsoft SharePoint 2010 and PowerPivot on it. Well I was really impressed by the speed of the system, I booted in 3 times as fast an all Office products would directly open when I clicked on a document, instead of waiting for the splash screen. I know 4GB of RAM is not enough for a Microsoft SharePoint 2010 PowerPivot development machine, but with the help of the SSD I could manage it. But then I could not take snapshots of my host.

As I said before, VMware Workstation 7 is to slow for me on my hardware for running Microsoft SharePoint 2010 with PowerPivot, that’s why I started to look at hypervisors.

Pros
– Don’t have to no anything about hypervisors, just install windows host OS and then install VMware Workstation 7.0, it’s only a program.
– Supports not only Windows guest operating systems

Cons
– Must be installed on a host operating system (host operating systems consumes cpu, memory and disk space
– Is not free
– “Bad” performance compared to native boot

 

VMware ESXi (freeware)

Then in begin 2010 I learned about hypervisors. VMware has a free product ESXi 4, that can be installed on a system with a (32MB foot print, maximizing the space on the 80GB OS for Virtual Machines) and then you can run different virtual machine containing not only Microsoft OS but also Linux etc without installing a Host OS and having the possibility to take snapshots and backups of the virtual machines . So I created a bootable USB ESXi drive but found out my NIC and SATA controller where not supported, damn! Yes I know, ESXi is not supposed to be installed on a laptop but it would have been nice.

Pros
– Freeware
– No host OS (so not need to snapshot or backup host, only snapshot and backup virtual machines)
– 32 MB footprint
– Supports not only Windows guest operating systems
– Can run Microsoft Windows XP virtual machines
– Can boot from USB without installing

Cons
– Can’t native boot from virtual machines (so a performance impact, but far better then VMware Workstation)
– Could not get it to work with my DELL laptop

 

Microsoft Hyper-V 2008 R2 (freeware)

In 2010 Microsoft released there hypervisor: Microsoft Hyper-V 2008 R2 and it’s free! What did you say, is Microsoft releasing a product that’s free of charge, the answer is; YES. It can be downloaded, here: http://www.microsoft.com/downloads/details.aspx?FamilyID=48359dd2-1c3d-4506-ae0a-232d0314ccf6&displaylang=en it’s a 1,5 GB ISO. Installed it and after installing I could boot from a VHD file created with Microsoft Windows 2008 R2

Pros
– Freeware
– Native boot from VHD, maximizing performance and hardware possibilities
– No host OS (so not need to snapshot or backup host, only snapshot and backup virtual machines)
– 6GB footprint (after installing)
– Can boot from USB without installing

Cons
– Supports only booting from Microsoft Windows 7 or Microsoft Windows Server 2008 R2
– Have to use a “workstation” virtualization product in a booted virtual machine to manage other virtual machines

 

What do I exactly use for developing Microsoft SharePoint 2010 PowerPivot applications

So today what do I exactly use for developing C# vs2008, C# vs2010 and SharePoint 2010 PowerPivot applications

  1. Laptop with Microsoft Hyper-V Server 2008 R2 (freeware) installed on a 2,5 inch 80GB SSD boot disk, a 500GB 7200 rpm 2,5 inch for data and virtual machines I don’t often use and 8GB of RAM.
  2. When I start the laptop I boot into a VHD containing Microsoft Windows 2008 R2, Microsoft SQL Server 2008 R2, Microsoft SharePoint 2010, Microsoft Office 2010 and the hyper visor role installed to manage other virtual machines. Because I primarily do self service BI work and VS2010 development this is the machine I want the best performance for. I use the hyper-v manager in the this virtual machine to start legacy virtual machines (VS2005 with SQL 2005 or VS2008 with SQL 2008)
  3. In the SharePoint 2010 virtual machine I keep 2 images up date date, a base Microsoft Windows 7 and a base Microsoft Windows Server 2008 R2 virtual machine. They serve as base for creating new virtual machines, see https://www.roelvanlisdonk.nl/?p=1530. They are updated every week and configured the way I want to, see https://www.roelvanlisdonk.nl/?p=1462
  4. In all I mange 6 virtual machines
    • Microsoft Windows 7 x64 – base for client virtual machines
    • Microsoft Windows Server 2008 R2 x64 – base for server virtual machines
    • Legacy 2005 development – clone of Microsoft Windows 7 x64 base containing VS2005, Office 2003, SQL Server 2005, SSIS 2005, SSRS 2005, SSAS 2005
    • Legacy 2008 development – clone of Microsoft Windows 7 x64 base containing VS2008, Office 2007, SQL Server 2008, SSIS 2008, SSRS 2008, SSAS 2008
    • SharePoint 2010 development (native boot), clone of Microsoft Windows Server 2008 R2 x64, containing VS2010, SharePoint 2010 with PowerPivot, Office 2010, SQL Server 2008 R2, SSIS 2008 R2, SSRS 2008 R2, SSAS 2008 R2
    • VPN – clone of Microsoft Windows 7 x64 base containing VPN connections and remote desktop shortcuts to customer machines (I use a virtual machine for this purpose, because, when connected to the VPN I don’t have access to the rest of the network)

 

Conclusion

Microsoft Hyper-V Server 2008 R2 rules:

  1. Creating new virtual machines in minutes, containing a fully patched windows host OS and configured the way I like it to be with the ability to boot from the virtual machines, maximizing performance
  2. Can use legacy development machines without rebooting (vs2005, vs2008 for legacy support)
  3. Install a full blown Microsoft SharePoint 2010 development server within 30 minutes on a new laptop or workstation and booting from it, maximizing performance

How to native boot Windows 7 from vhd (hyper-v) on an other machine with RAID, without getting the BSOD (blue screen of death)

I wanted to create one virtual machine and use (boot)  it on an other machine, but I was getting a Blue Screen Of Death (BSOD) every time I booted the virtual machine, even if I created the VHD in the Microsoft Windows 2008 R2 Hyper-V manager and tried to natively boot on that same machine from the virtual machine.

Cause

This was caused by the fact that I was using a RAID configuration on Machine A and also on Machine B and the RAID drivers where not supplied on the Windows 7 DVD. All drivers needed to boot Microsoft Windows 7 should be available on the virtual machine before you try to boot from the vhd.

 

Solution

Even if you are not using RAID configuration, best practice is to sysprep you’re virtual machine before you try to boot it on an other machine. If you’re using a RAID configuration, special graphics drivers or other drivers not on the Microsoft Windows 7 DVD, use dism.exe found in the “Windows Automated Installation Kit (AIK) for Windows® 7” to add drivers to you’re syspreped vhd.

These are the steps I used to boot from a VHD containing Microsoft Windows 2008 R2 or Microsoft Windows 7 on an other machine without getting the BSOD:

 

Creating the Virtual Machine

  • Machine A has Microsoft Windows 2008 R2 with hyper-v role installed
  • Create a Virtual Machine on Machine A, by using the hyper-v manager (Start > Administrative Tools > Server Manager > Roles > Hyper-V Manager. Make sure the disk is fixed to a maximum size (for example: 50GB). Machine B should have at least 50GB free disk space else the vhd won’t boot.
  • Create the virtual machine on C:\VHD\NotSysPreped, path to VHD should be C:\VHD\NotSysPreped\MyMachine.vhd
  • After installing Windows 7 or Windows Server 2008 R2 on it and after installing all you’re programs (except anti virus), shutdown the virtual machine
  • Install the Windows Automated Installation Kit (AIK) for Windows® 7 on Machine A, because we need the dism.exe tool. You could also use a tool like Virtual CloneDrive to copy the tool out of the downloaded *.iso file.
  • I will boot this virtual machine once a week to update it with the last Windows Updates (keeping this Virtual Machine up to date)

 

Pre-pair the Virtual Machine

Every time you want to use a copy of this virtual machine on other machine, execute the following steps:

  • Shutdown the Virtual Machine on Machine A
  • Copy the file C:\VHD\NotSysPreped\MyMachine.vhd to C:\VHD\SysPreped\MyMachine.vhd. We create a copy of the vhd, because we want the original virtual machine to keep working.
  • Create a new Virtual Machine based on the copied C:\VHD\SysPreped\MyMachine.vhd file
  • Boot this new Virtual Machine
  • In the Virtual Machine execute C:\Windows\System32\sysprep\sysprep.exe
  • image
  • Choose Enter System Out-of-Box Experience (OOBE)
  • Check “Generalize”
  • Choose “Shutdown”
  • Press OK

The following steps are only needed when you are using drivers on Machine B, that are not supplied on the Windows 7 DVD (for example: when you are using a RAID configuration).

  • After the virtual machine has shutdown, run CMD on Machine A
  • Attach the C:\VHD\SysPreped\MyMachine.vhd file, so it can be used by the dism.exe tool:
    • In the cmd dialog enter:
    • diskpart
    • select vdisk file=C:\VHD\SysPreped\MyMachine.vhd
    • attach vdisk
    • assign letter=v
    • exit
  • Copy you’re RAID drivers to Machine A on C:\Drivers
  • Add RAID drivers by using the dism.exe tool:
    • In the cmd dialog enter:
    • dism.exe /image:V:\ /Add-Driver /driver:C:\Drivers\mydriver.inf

 

Booting from the Virtual Machine on Machine B

  • Machine B must be running Windows Server 2008 R2 or Windows 7
  • Boot Machine B
  • Copy the C:\VHD\SysPreped\MyMachine.vhd from Machine A to Machine B C:\VHD\SysPreped\MyMachine.vhd
  • Edit the boot manager by using the bcdedit.exe tool:
    • bcdedit /copy {current} /d “MyMachine Description
    • The previous statement returns a GUID like: {aa2e3972-7a31-11df-987b-b52175dc348f}
    • bcdedit /set {aa2e3972-7a31-11df-987b-b52175dc348f} device vhd=[C:]\VHD\SysPreped\MyMachine.vhd
    • bcdedit /set {aa2e3972-7a31-11df-987b-b52175dc348f} osdevice vhd=[C:]\VHD\SysPreped\MyMachine.vhd
    • bcdedit /set {aa2e3972-7a31-11df-987b-b52175dc348f} detecthal on
    • bcdedit /set hypervisorlaunchtype auto
    • The previous statement is only needed when the virtual machine is running Microsoft Windows 2008 R2 with the hyper-v role enabled.
  • Reboot Machine B
  • After rebooting you should see two entries one with the description “Windows 7” and an other with the description “MyMachine Description
  • You should now be able to boot the virtual machine on Machine B without getting the BSOD!

A small demo ASP .NET 4.0 Web Application, using Entity Framework in a Master – Details view

I just created a small demo ASP .NET 4.0 Web Application, it uses:

– ASP .NET 4.0

– Ajax

– Declarative DataBinding using a EntityDataSource

– DetailsView (master – details view, by using a RadGrid and a DetailsView)

– Entity Framework 4.0

– Masterpage and contentpages

– Microsoft SQL Server 2008 R2 RTM sample database AdventureWorks

– Stylesheet for the master page and per contentpage 1 styelsheet

– Telerik RadGrid

 

Screendump Master View (ProductCategoryOverview)

image

When you click on the “Edit” link a new page will be shown (ProductCategoryDetails.aspx)

 

Screendump Detials View (ProductCategoryDetails.aspx)

image

 

Site.master

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Demo.WebApplication.Site" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>PowerPivot Demo WebApplication</title>
<link href="Styles/Master.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="Form1" runat="server" class="form">
<telerik:RadScriptManager ID="generalRadScriptManager" runat="server" />
<!-- One RadAjaxManager for all content pages --> 
<telerik:RadAjaxManager ID="generalRadAjaxManager" runat="server" />
<!-- One RadAjaxLoadingPanel for all content pages --> 
<telerik:RadAjaxLoadingPanel ID="generalRadAjaxLoadingPanel" runat="server" BackgroundPosition="Center" Skin="Default" />
<div class="page">
<div class="inside">
<div class="header">
<img alt="PowerPivot Logo" src="Images/PowerPivot_Logo.png"/>
<!-- All postback's in the RadAjaxPanel1 will be converted to AJAX postback's and the page will not flicker on navigation -->
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="generalRadAjaxLoadingPanel">
<div class="navigation">
<div class="navigationPrimary">
<ul> 
<li><asp:LinkButton ID="administrationLinkButton" runat="server" onclick="AdministrationLinkButton_Click">Manage</asp:LinkButton></li>
<li><asp:LinkButton ID="zakelijkLinkButton" runat="server" onclick="AdministrationLinkButton_Click">View</asp:LinkButton></li>
</ul>
</div>
<div class="navigationSeparator"></div>
<div class="navigationSecondairy">
<ul> 
<li><asp:LinkButton ID="customerLinkButton" runat="server" onclick="CustomerLinkButton_Click">Customer</asp:LinkButton></li>
<li><asp:LinkButton ID="ProductLinkButton" runat="server" onclick="ProductLinkButton_Click">Product</asp:LinkButton></li>
<li></li>
</ul>
</div>
</div>
</telerik:RadAjaxPanel>
</div>
<div class="content">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
<div class="footerPlaceholder"></div>
</div>
<div class="footer">
<ul class="footerLeftNav">
<li>Contact Us</li>
<li>Privacy Statement</li>
</ul>
</div>
</div>
</form>
</body>
</html>

 

ProductCategoryOverview.aspx

<%@ Page MasterPageFile="~/Site.master"  Language="C#" AutoEventWireup="true" CodeBehind="ProductCategoryOverview.aspx.cs" Inherits="Demo.WebApplication.ProductCategoryOverview" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="Styles/ProductCategoryOverview.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="PageContent" ContentPlaceHolderID="MainContent" runat="server">
<telerik:RadGrid 
ID="PageRadGrid"
AllowFilteringByColumn="True"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False"
ShowStatusBar="True"
DataSourceID="PageDataSource"
EnableLinqExpressions="false"
runat="server"
PageSize="25">
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
<MasterTableView CommandItemDisplay="Top">
<NoRecordsTemplate>
<asp:Label runat="server" ID="noItemsLabel" Text="No records found!"></asp:Label>
</NoRecordsTemplate>
<CommandItemTemplate>
<a class="addLink" href="ProductCategoryDetails.aspx?Id=-1">Add new record</a>
<a class="refreshLink" href="ProductCategoryOverview.aspx">Refresh</a>
</CommandItemTemplate>
<SortExpressions>
<telerik:GridSortExpression FieldName="Name" SortOrder="Ascending" />
</SortExpressions>
<Columns>
<telerik:GridHyperlinkColumn
AllowFiltering="false"
UniqueName="EditColumn"
DataTextFormatString="Edit"
DataTextField="ProductCategoryID"
DataNavigateUrlFields="ProductCategoryID"
DataNavigateUrlFormatString="~/ProductCategoryDetails.aspx?Id={0}"
meta:resourcekey="EditColumn">
</telerik:GridHyperlinkColumn>
<telerik:GridButtonColumn 
CommandName="Delete" 
meta:resourcekey="DeleteColumn"
UniqueName="DeleteColumn"  
ConfirmText="Delete this customer?" 
Text="Delete">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn 
AutoPostBackOnFilter="true"
CurrentFilterFunction="EqualTo"
DataField="ProductCategoryID"
FilterControlWidth="100px"
HeaderText="Id"
meta:resourcekey="ProductCategoryIDColumn" 
UniqueName="ProductCategoryID" 
SortExpression="ProductCategoryID"  
ShowFilterIcon="true">
<ItemStyle Width="100px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn 
AutoPostBackOnFilter="true"
CurrentFilterFunction="Contains"
DataField="Name"
FilterControlWidth="100px"
HeaderText="Name"
meta:resourcekey="NameColumn" 
UniqueName="Name" 
SortExpression="Name"  
ShowFilterIcon="true">
<ItemStyle Width="100px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn 
AutoPostBackOnFilter="true"
CurrentFilterFunction="Contains"
DataField="rowguid"
FilterControlWidth="200px"
HeaderText="rowguid"
meta:resourcekey="rowguidColumn" 
UniqueName="rowguid" 
SortExpression="rowguid"  
ShowFilterIcon="true">
<ItemStyle Width="200px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn 
AutoPostBackOnFilter="true"
CurrentFilterFunction="Contains"
DataField="ModifiedDate"
FilterControlWidth="200px"
HeaderText="ModifiedDate"
meta:resourcekey="ModifiedDateColumn" 
UniqueName="ModifiedDate" 
SortExpression="ModifiedDate"  
ShowFilterIcon="true">
<ItemStyle Width="200px" />
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:EntityDataSource 
ID="PageDataSource" 
runat="server" 
EnableDelete="true" 
EnableInsert="true" 
EnableUpdate="true"
ConnectionString="name=AdventureWorksEntities"
DefaultContainerName="AdventureWorksEntities"
EntitySetName="ProductCategory"
>
</asp:EntityDataSource>
</asp:Content>

ProductCategoryDetails.aspx

<%@ Page MasterPageFile="~/Site.master" Language="C#" AutoEventWireup="true" CodeBehind="ProductCategoryDetails.aspx.cs" Inherits="Demo.WebApplication.ProductCategoryDetails" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="Styles/ProductCategoryDetails.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="PageContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:DetailsView 
ID="PageDetailsView" 
runat="server"
DataSourceID="PageDataSource"
AllowPaging="false"
AutoGenerateDeleteButton="true"
AutoGenerateEditButton="true"
AutoGenerateInsertButton="true"
AutoGenerateRows="false"
EmptyDataText="No record found!"
DataKeyNames="ProductCategoryID" 
onitemcommand="PageDetailsView_ItemCommand">
<Fields>
<asp:BoundField
DataField="ProductCategoryID"
HeaderText="ProductCategoryID">
</asp:BoundField>
<asp:BoundField
DataField="Name"
HeaderText="Name">
</asp:BoundField>
<asp:BoundField
DataField="rowguid"
HeaderText="rowguid">
</asp:BoundField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="ModifiedDateHeaderLabel" runat="server" Text="ModifiedDate"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<div>
<asp:Label ID="ModifiedDateLabel" runat="server" Text='<%# Bind("ModifiedDate") %>'></asp:Label>
<asp:LinkButton ID="ModifiedDateLinkButton" runat="server" CssClass="generateLinkButton" CommandName="GenerateModifiedDate">Generate</asp:LinkButton>
</div>
</ItemTemplate>
<EditItemTemplate>
<div>
<asp:TextBox ID="ModifiedDateTextBox" runat="server" Text='<%# Bind("ModifiedDate") %>'></asp:TextBox>
<asp:LinkButton ID="ModifiedDateLinkButton" runat="server" CssClass="generateLinkButton" CommandName="GenerateModifiedDate">Generate</asp:LinkButton>
</div>
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:EntityDataSource 
ID="PageDataSource" 
runat="server" 
EnableDelete="true" 
EnableInsert="true" 
EnableUpdate="true"
ConnectionString="name=AdventureWorksEntities"
DefaultContainerName="AdventureWorksEntities"
EntitySetName="ProductCategory"
Where="it.[ProductCategoryID]=@ProductCategoryID">
<WhereParameters> 
<asp:QueryStringParameter DbType="Int32" Name="ProductCategoryID" QueryStringField="Id" /> 
</WhereParameters> 
</asp:EntityDataSource>
</asp:Content>

 

Note: In my application I must use “it” before the column name in the Where property of the EntityDataSource, else I will get an exception:

System.Web.HttpUnhandledException (0x80004005): Exception of type ‘System.Web.HttpUnhandledException’ was thrown. —> System.Data.EntitySqlException: ‘ProductCategoryID’ could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near escaped identifier, line 6, column 1. at System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at System.Web.UI.WebControls.BaseDataBoundControl.DataBind() at System.Web.UI.WebControls.DetailsView.DataBind() at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() at System.Web.UI.WebControls.DetailsView.EnsureDataBound() at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() at System.Web.UI.Control.EnsureChildControls() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.productcategorydetails_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\f1d0d8b4\9eb9cfbd\App_Web_2z53k4nc.5.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously

 

ProductCategoryDetails.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Demo.WebApplication
{
public partial class ProductCategoryDetails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PageDetailsView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (this.PageDetailsView.DefaultMode == DetailsViewMode.ReadOnly)
{
if (e.CommandName.Equals("GenerateModifiedDate", StringComparison.CurrentCultureIgnoreCase))
{
Label modifiedDateLabel = this.PageDetailsView.FindControl("ModifiedDateLabel") as Label;
modifiedDateLabel.Text = DateTime.Now.ToString();
}
}
else
{
if (e.CommandName.Equals("GenerateModifiedDate", StringComparison.CurrentCultureIgnoreCase))
{
TextBox modifiedDateTextbox = this.PageDetailsView.FindControl("ModifiedDateTextbox") as TextBox;
modifiedDateTextbox.Text = DateTime.Now.ToString();
}
}
}
}
}

 

Master.css

*
{
margin: 0px; /* All elements start with 0px margin */
padding: 0px;  /* All elements start with 0px padding */
}
html
{
height: 100%; /* Must be 100% for footer at the bottom of the page */
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
font-weight: normal;
color: #222;
}
body
{
height: 100%; /* Must be 100% for footer at the bottom of the page */
}
form
{
height: 100%; /* Must be 100% for footer at the bottom of the page */
}
a
{
color: #222;
text-decoration: none;
}
a:hover
{
color: #222;
text-decoration: underline;
}
div.page
{
margin-right: auto; /* Center the page */
margin-left:auto; /* Center the page */
height: 100%;  /* Must be 100% for footer at the bottom of the page */
text-align: left;
width: 1000px; /* Fixed width for screen resolution 1024px optimalisation */
}
div.inside
{
border-left: 1px solid rgb(224,225,226);
border-right: 1px solid rgb(224,225,226);
min-height: 100%;  /* Must be 100% for footer at the bottom of the page, using min-height instead of height allows content to be larger then intial page size */
margin-bottom: -33px; /* Negative bottom margin is used for correct the 100% height with the height of the footer, else vertical scrollbars will be shown */
}
div.header
{
padding: 10px 0px 8px 0px;
}
div.header img
{
height: 60px;
margin-left: 20px;
}
div.content
{
color: #666;
font-size: 70%;
padding: 20px 15px 15px 15px;
}
div.navigation
{
border-bottom: 2px solid rgb(143,208,64);
position: absolute;
top: 0px;
width: 998px;
}
div.navigationSeparator
{
border-top: 1px solid rgb(222,222,222);
margin-left: 279px;
}
div.navigationPrimary ul
{
height: 26px;
margin-top: 13px;
padding-left: 299px;
}
div.navigationPrimary ul li
{
background: url(../Images/TabLeft.gif) no-repeat scroll left top;
float: left; /* Makes the unoderdered list flow horizontal instead of vertical */
font-weight: bold;
font-size: 75%;
height: 26px;
line-height: 26px;
list-style-type: none; /* Don't display bullets */
margin: 0px 4px 0px 0px;
text-decoration: none;
text-transform: uppercase;
white-space: nowrap;
}
div.navigationPrimary ul li a
{
background: url(../Images/TabRight.gif) no-repeat scroll right top;
float: left;
height: 26px;
line-height: 26px;
padding: 0px 15px 0px 15px;
}
div.navigationPrimary ul li a:hover
{
color: rgb(143,208,64);
}
div.navigationSecondairy ul
{
padding-left: 310px;
margin-top: 
}
div.navigationSecondairy ul li
{
border-left: 1px solid rgb(143,208,64);
float: left; /* Makes the unoderdered list flow horizontal instead of vertical */
font-size: 80%;
list-style-type: none; /* Don't display bullets */
margin: 10px 12px 10px 0px;
padding-left: 10px;
white-space: nowrap;
}
div.navigationSecondairy ul li a
{
float: left;
}
div.navigationSecondairy ul li a:hover
{
color: rgb(143,208,64);
}
div.footerPlaceholder
{
height: 33px; /* The height should be equal to the full height of the footer (including any padding or borders you may add). Without the "footerPlaceholder" div, the content will flow beneath the footer */
}
div.footer
{
background-color: rgb(143,208,64);
color: rgb(255,255,255);
font-size: 60%;
padding: 10px 46px 10px 46px;
width: 906px;
}
ul.footerLeftNav
{
margin: 0px;
padding: 0px;
page-break-inside: avoid;
list-style-position: outside;
list-style-type: none;
}
ul.footerLeftNav li
{
display: inline;
padding-right: 18px;
}

 

ProductCategoryOverview.css

div.content
{
padding-top: 30px;
}
div.content a:hover
{
text-decoration: underline;
}
a.addLink
{
background: url(../Images/AddCross.gif) no-repeat scroll left center;
cursor: pointer;
float: left;
margin: 5px 0px 5px 10px;
padding-left: 20px;
}
a.refreshLink
{
background: url(../Images/Refresh.gif) no-repeat scroll right center;
cursor: pointer;
float: right;
margin: 5px 10px 5px 0px;
padding-right: 22px;
}

 

ProductCategoryDetails.css

div.content a.generateLinkButton
{
margin-left: 25px;
color: Blue;
}
div.content table
{
border: none;
}
div.content td
{
border: none;
padding: 2px 5px 2px 5px;
white-space: nowrap;
}
div.content input[type=text]
{
width: 300px;
}