Archive for June, 2008

ASP.NET DataGrid

The DataGrid server control is one of the most powerful—and most poorly documented—built-in features of the .NET Framework. Sure, getting the DataGrid to chew up and spit out your ADO.NET data is easy. But if you don’t properly understand its advanced workings, you’ll spend more than a few hours cursing your computer. For example, deleting data from a DataGrid is far from intuitive. To help you handle the task, I’ll show you how to quickly set up a DataGrid that has a delete button with a delete confirmation popup and explain how to process the delete command in the database.

Before you jump into the specifics of deleting from a DataGrid, you should have a working knowledge of how the DataGrid control works. If you don’t, you’ll find many Internet resources that will help you get up to speed. In particular, I recommend “An Extensive Examination of the DataGrid Web Control.” It’s a great jumping-off point.

Getting started
We’re going to begin with a blank ASP.NET page. Add the code in Listing A to the HTML view.

As you can see, we’ve added a hidden column that will store the primary key for each record. This will allow us to do some work with the data later. So we have a basic DataGrid, but we still need to feed it data. Switch to the codebehind view and add the code in Listing B.

For this example, we’ll employ the trusty Northwind database to play with some data. For brevity, we’re calling the database directly from our codebehind, but usually, such commands are moved to the Data Access Layer for a completely modular design. (I’ll explain more about application architecture in a future article.) Compile and run the page, and you’ll see a basic, no-frills DataGrid.

In most real-world situations, however, users won’t just need to see data; they’ll need to work with it. So in Listing C, you’ll add a delete button to the last column in the grid by changing the <columns> section of the grid code.

As you can see, this code uses a template column with a button instead of a ButtonColumn. Why? It’s a purely semantic decision. If you want to later, you can add more buttons to the column in a similar fashion without having to rewrite a bunch of code. You can really go either way.

No delete button would be complete without a confirmation dialog box, so add Listing D code to the codebehind.

Obviously, we can’t do anything with the button until it has been created, and it won’t be created until the row is bound to the data. So we’ll employ the ItemDataBound event to trigger the addition of this code.

The Framework makes it easy to add a JavaScript command to nearly any ASP.NET object by using the Add() method of the Attributes collection. But first, we need to find the button in the Controls collection. The Framework comes to the rescue once again, this time with the FindControl method. Using the CType function, set the variable l to the instance of the current item’s button and you can operate on it.

Compile and run the page. Now, when you click the delete button, you’ll get a dialog box confirming your request. Click Cancel, and the postback event will not fire. Click OK, and the form will be submitted. Right now, however, nothing will happen, because we haven’t coded the event handler yet. Let’s change the codebehind to handle the ItemCommand event.

In Listing E, the hidden ID column identifies which database item will be deleted. As I mentioned earlier, the actual delete processing should be contained in a separate set of classes for data access. Further, you should never use direct operations on a database, as they leave you open to SQL injection attacks.

The ItemCommand approach is more than adequate if you’re working with only one type of grid command. Things get a little trickier when you add paging functionality to the mix. Regardless of whether the default or custom paging modes are used, the page links are actually LinkButton objects, which are added programmatically. This means that they respond to ItemCommand events like any other LinkButton. Future articles will dive deeper into the DataGrid and look at implementing the not-so-automatic built-in paging system.

The same method is and for gridview

June 25, 2008 at 2:47 pm Leave a comment

Enable IntelliSense in Your Documents

Visual Studio has provided an XML editor that offers IntelliSense for any given XML schema since Visual Studio 2003. Microsoft upgraded this XML editor in Visual Studio 2005.In VS 2003, IntelliSense works if the namespace declaration URI (Uniform Resource Identifier) matches one of the schemas in your local VS folder. This has always worked well and continues to work in VS 2005, but it’s actually the wrong approach to validate XML schemas.

I’ll cover the limitations of the VS 2003 approach for providing IntelliSense in your XML documents, including why you shouldn’t use namespace URIs for schema validation. I will also cover a better approach, using the XML-Schema Instance (XSI) namespace and how you can use it to solve the problems presented by the original implementation. Finally, I will show you how to create an example that leverages the new XML editor in VS 2005, using the XSI namespace to perform validation and provide IntelliSense against any locally or remotely hosted XML schemas.

There are many reasons why you might want to edit XML documents in Visual Studio. For example, you might want to use it to edit a Web.Config file, an XSL Transformation (XSLT), or any XML input/configuration files for your own custom applications. To enable XML IntelliSense in Visual Studio 2003, locate your schema, then copy it to C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml. Next, open a new XML document, and reference the schema by its namespace URI in the root element.

By default, VS 2003 provides a File/New XSLT template, but doesn’t include the schema. You can download the freely available schema from Fesersoft. By copying the schema to the location mentioned above, you will start to get IntelliSense. Updating the File/New xsltfile.xslt template is optional. It is located in C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\NewFileItems.

This has been a good solution for providing IntelliSense for XML documents, and my own company has been using it for more than two years. It’s effective, but has a couple weaknesses.

The first is basically an inconvenience; the schemas must reside locally. This creates a problem when XML schemas need to be distributed to a team of developers, especially if the schemas are evolving and/or are not centrally located. You can overcome this problem by scripting Visual Studio’s OnStartupComplete event to download the schemas from multiple locations to the local drive.

The second problem with this technique relates to a fundamental XML issue that occurs when you use XML namespace URIs to locate schemas for validation and IntelliSense. The purpose of XML namespaces is for qualifying elements and attributes, similar to how people qualify a first name with a last name. The syntax of a namespace declaration is xmlns:prefix=”anyURI” where you can express the URI as either a Uniform Resource Locator (URL) or a Uniform Resource Name (URN). In other words, you can write a namespace URI as either or urn:www-foo-com.

What’s in a Name(space)?
It is mere coincidence that many namespace URIs look like valid URLs. In fact, if you navigate to XSLT’s namespace declaration URL (, you’ll get a schema that reads: “Someday a schema for XSL Transformations will live here.” A namespace URI is nothing more than a label, and technically, it provides no information about the location of the corresponding schema. This explains why the schema files must reside locally in VS 2003. There is no other way to locate them.

The problem remains: You need a way to associate an XML document’s namespace URIs to their schema locations. You might be aware that the XML-Schema Instance (XSI) namespace is used to define types, such as xsi:type=”integer.” One of the more powerful and lesser known uses of this namespace is its ability to associate XML schemas.

Let’s examine the name of the XML-Schema Instance namespace. In object-oriented programming, you have classes and objects that represent the static compile time and dynamic runtime parts of an application. Objects are running instances of classes. XML behaves similarly; a schema document is like a class. When you create a new XML document that uses a schema, it’s like creating an object instance of a class. This new XML document is an instance document. The name “XML-Schema Instance” implies that there is a separation of a schema and its instance. It also implies that you will use the schema within an instance document.

Conversely, namespace declarations can be used in both schema documents and instance documents. Namespace declarations provide uniquely named labels, but the XSI namespace provides the ability to associate an instance document with its schema(s) and to reference the schema’s types (see Table 1).

The XSI namespace has two attributes for associating schemas: xsi:noNamespaceSchemaLocation and xsi:schemaLocation. You can use xsi:noNamespaceSchemaLocation to reference your schema if the schema does not define a target namespace:

<foo xmlns:xsi="?"

June 25, 2008 at 2:41 pm Leave a comment

sharepoint 2003 info

With SharePoint Portal Server, you are able to utilize your existing information effectively, and to capture information in new ways that make sense for your business. You can rapidly deploy an out-of-the-box portal site and easily use Web-Parts technology to customize a Web-based view of your organization.

You have the ability to quickly deploy an out-of-the-box portal solution that facilitates finding, creating, and sharing all of your mission-critical data from a browser-based interface. The portal features search technology developed by Microsoft Research that enables you to search file shares, Web servers, Microsoft Exchange Server public folders, Lotus Notes, and Windows SharePoint Services sites out of the box. You can organize documents and information by topic and browse for relevant content.

SharePoint Portal Server can be extended by adding additional Web application functionality. SharePoint Portal Server is designed around industry and Internet standards, such as OLE DB, Microsoft ActiveX® Data Objects (ADO), Extensible Markup Language (XML), and Microsoft Web Distributed Authoring and Versioning (WebDAV), making it easy for developers familiar with these standards. Due to this support of standards, the use of tools like Microsoft Visual Studio® allows you to integrate Active Server Pages (ASP) functionality into the portal.

Everyone works with documents, but not everyone has the ability to use technology to structure how they work with their colleagues on these documents. The process from document creation through intranet publishing can be a string of disjointed actions, unconnected with business processes. SharePoint Portal Server includes features like document locking, versioning, and publishing and makes these features accessible to the average user. It delivers easy-to-use, document-management features that are integrated with the tools and applications that are used to create and manage documents, with Microsoft Windows® Explorer and Microsoft Office 2000 applications like Microsoft Word, Microsoft Excel, and Microsoft PowerPoint®.

Using SharePoint Portal Server, you can also save and check documents into the document store, capturing business-relevant metadata in Document Profile forms. You can also tailor forms to your organization. Tracking changes though multiple drafts as a document is edited, reviewed, and approved is accomplished using integrated approval routing. This occurs prior to publishing for public viewing on the intranet dashboard site. You can also roll back to a previous version of a document. Look for features like Document Collaboration, Profiling, Lifecycle Management, and Web-based document management through a browser.

Locating information in any organization can be challenging. In addition, wading through the different forms, file formats, and storage locations that information requires (documents on file servers, HTML pages on Web servers, or e-mail on messaging servers), and finding what you need when you need it, can be difficult. People need a consistent place to access needed information—and in a structured way that makes sense. Intranet portals have become the place where such information is aggregated, organized, and searchable.

With SharePoint Portal Server, you have the power of Microsoft’s robust search technologies to create an intranet site that lets you easily access key content from a broader set of enterprise information. In addition to having one comprehensive place in the portal to search, you can also set the portal to have information come to you with information subscription—directly delivering new and changed content notifications.

Some of the features to explore in SharePoint Portal Server are Subscriptions, Category Browsing, Best Bets in Search results, and extensibility using third-party, or your own, digital dashboard Web Parts.

June 25, 2008 at 2:35 pm Leave a comment

Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta

There is no doubt that VS 2008 and .NET 3.5  totally rocks! ScottGu’s division keeps pushing these products and constantly improving developer’s productivity and shortening development cycle.

This time MS is preparing to release .NET 3.5 SP1 and VS 2008 SP1 releases.

In short here are improvements:

Improvements for Client Development
  • ASP.NET Data Scaffolding Support (ASP.NET Dynamic Data)
  • SP.NET Routing Engine (System.Web.Routing)
  • ASP.NET AJAX Back/Forward Button History Support
  • ASP.NET AJAX Script Combining Support – Omar Al Zabir wrote an extensive article about this approach.
  • Visual Studio 2008 Performance Improvements HTML Designer and HTML Source Editor
  • Visual Studio 2008 JavaScript Script Formatting and Code Preferences
  • Better Visual Studio Javascript Intellisense for Multiple Javascript/AJAX Frameworks – who can blame MS that force us to use their JS framework now?!
  • Visual Studio Refactoring Support for WCF Services in ASP.NET Projects
  • Visual Studio Support for Classic ASP Intellisense and Debugging – I am wondering when this technology will be declared dead 🙂 (This is what I used in my first web apps too :))
Improvements for Client Development
  • Application Startup and Working Set Performance Improvements
  • New .NET Framework Client Profile Setup Package
  • New .NET Framework Setup Bootstrapper for Client Applications
  • ClickOnce Client Application Deployment Improvements
  • Windows Forms Controls
  • WPF Performance Improvements
  • WPF Data Improvements
  • WPF Extensible Shader Effects
  • WPF Interoperability with Direct3D
VS 2008 for WPF Improvements
  • Several performance improvements
  • Events tab support within the property browser
  • Ability to sort properties alphabetically in the property browser
  • Margin snaplines which makes form layout much quicker
  • Better designer support for TabControl, Expander, and Grid
  • Code initiated refactoring now updates your XAML (including both control declarations and event declarations in XAML)
  • Go to Definition and Find All References now support things declared in XAML
Data Development Improvements
  • SQL 2008 Support
  • ADO.NET Entity Framework and LINQ to Entities
  • ADO.NET Data Services
WCF Development Improvements
  • Significant scalability improvements (5-10x) in Web-hosted application scenarios
  • Support for using ADO.NET Entity Framework entities in WCF contracts
  • API usability improvements with DataContract Serializers, and with the UriTemplate and WCF web programming models
  • Enhanced TestClient support within VS 2008 SP1
  • New Hosting Wizard in VS 2008 SP1 for WCF Service Projects
  • Improved debugging support in partial trust scenarios
VB and C# Improvements !!!

June 22, 2008 at 5:39 am Leave a comment

June 2008
« Apr   Jul »