Sunday, March 23, 2008

Creating ExRepeater Control from scratch with grouping support - Part 1

In ASP.NET we have repeater control which is cool...!!, last week I was developing a website in which I want the content to be grouped alphabetically. For example if we have a list of countries, I want it to be grouped alphabetically with corresponding alphabet on the top the group. But our old friend repeater control couldn't meet this requirement. So I thought about creating a custom repeater controls, I call this ExRepeater(Extended Repeater), this control helps you to group the items in the repeater according to any fields you specify, more over the Grouping Logic can be decided by the user. That is the control doesn't provide any grouping logic from out-of-box.


So let starts creating this...


I have create a control library project with the name PlugAI.Controls.Web.UI.ExRepeater and added a class called ExRepeater which is derived from the CompositeDataBoundControl




using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Collections;
using System.Drawing.Design;
using System.Data;
using System.ComponentModel;

[assembly: TagPrefix("PlugAI.Controls.Web.UI.ExRepeater", "PlugAI")]

namespace PlugAI.Controls.Web.UI.ExRepeater
{

public class ExRepeater : CompositeDataBoundControl
{
.....
}
}



After creating this class, you have override the CreateChildControls(....) method, this method is responsible for generating the output we want.



protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
{
int count = 0;
if (dataBinding)
{
........

...........
foreach (object dataItem in dataSource)
{
if (itemTemplate != null)
{
....................
ExRepeaterItem item = new ExRepeaterItem(count++,ExListItemType.Item);
item.DataItem = dataItem;
ItemTemplate.InstantiateIn(item);

................

this.Controls.Add(item);
item.DataBind();
...............

}

}

................
}
return count;
}


Here first we check whether we want the data binding, if required we will take each data item from the binded data source and create corresponding controls from the template.


In the next post I will explain about



  • Raising events, like ItemCommand etc..

  • Creating a templated control

  • Developing the Grouping Logic

  • Creating designer for the Repeater Control

  • Finally a sample webpage with ExRepeater control.


Saturday, March 22, 2008

Syntax highlighting in blogger

If you want syntax highlighting in your blog post, you could use the syntaxhighlighter. For that follow the steps below...

1) First download the syntaxhighlighter from here

2) Unzip the file and upload the required files to any server (you could use google pages)

- clipboard.swf *
- shCore.js *
- SyntaxHighlighter.css * (this is inside the styles folder)
- shBrushCSharp.js (for C# )
- shBrushCss.js (for CSS)
etc...

3) Now goto the blogger, Layout->Edit HTML and include these files like this (at the end)


<!-- end outer-wrapper -->
<!-- Syntax Highlighter -->
<link href="http://[yourserver]/SyntaxHighlighter.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="[yourserver]/shCore.js" />
<script language="javascript" src="[yourserver]/shBrushCSharp.js"/>
<script language="javascript" src="[yourserver]/shBrushCss.js"/>
<script language="javascript" src="[yourserver]/shBrushXml.js"/>
<script language="javascript">
dp.SyntaxHighlighter.ClipboardSwf = '[yourserver]/clipboard.swf';
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
</script>
<!-- Syntax highlighter ends -->


For more information on how to use, visit here http://code.google.com/p/syntaxhighlighter/wiki/Usage

Saturday, January 26, 2008

VS 2008 - property code snippet.

I was working on a .NET 2.0 project in VS 2008 and I liked the new IDE but one thing I found that missing was , property code snippet that comes with the VS 2008 IDE doesn't have the VS 2005 style property snippet. VS 2008 doesn't create the private variable for the property, it creates only the Automatic Property(new feature :) ). But it is not useful for .NET 2.0 project because version framework 2.0 doesn't support automatic property. So if you want a VS 2005 property code snippet in VS 2008 follow the steps given below :

1. Create a file called proc.snippet
2. Copy the content below and save


<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propc</Title>
<Shortcut>propc</Shortcut>
<Description>Code snippet for property and backing field</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[private $type$ $field$;
public $type$ $property$
{
get { return $field$;}
set { $field$ = value;}
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>



3. Copy the file to the below location

C:\Documents and Settings\[User]\My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets


wow ! Now you have a new code snippet.

Try using propc to get the code snippet in the IDE

Sunday, January 20, 2008

Extended HyperLink - ASP.NET custom control

This is an extended HyperLink control which has new feature to disable the spam bots and crawlers from extracting your secure links.

For disable the bots visibility, you just need to set the Crawlable property to False. Default value of this property is True that means links are visible to the bots, if we set this to False links won't be visible to bots. You could also change this using the Smart Tag :)

How to use :

<PlugAI:ExHyperLink ID="ExHyperLink1" runat="server" Crawlable="False" NavigateUrl="http://www.google.com">ExHyperLink</PlugAI:ExHyperLink>


In the above screen shot, you could see two links one with Crawlable set to True and other to False and both links are pointing to same location ie http://www.google.com . The Crawlable is set to False for the second link that is why its link is unreadable even after looking into the view source.

Please download this from here

Saturday, October 13, 2007

Custom TreeView Layout in WPF

From this to

this...



This article discusses how to customize the item layout in a WPF TreeView. The layout we will examine is quite similar to an "org chart", where each level of items is displayed in a horizontal row directly beneath their respective parent. Along the way we will see how the power of templates and styles in WPF can provide incredible flexibility for customizing an application's user interface.

This article is not for WPF beginners. It assumes that you already have knowledge of XAML, control templates, styles, triggers, hierarchical data templates, data binding, and other fundamentals of WPF.

I also posted another article regarding layout customization for the TreeView control. If you are interested in seeing another way that the TreeView can be customized, you might want to read Advanced Custom TreeView Layout in WPF.

Read more

Tuesday, October 9, 2007

WPF ribbon control


Company: devcomponents.com

Wpf-Ribbon™ is the fully compliant Office 2007 style Ribbon control developed from ground-up for Windows Presentation Foundation

We released world's first Ribbon control for Windows Forms back in 2005 and using that experience and new WPF platform we developed world's first WPF Ribbon control. Wpf-Ribbon™ is designed for developing professional business applications with WPF.

Partial list of Wpf-Ribbon™ features:

  • Supports all required Office 2007 UI design elements. For details see below...
  • Automatic intelligent Ribbon resizing
  • Application menu support
  • Contextual groups support
  • Complete Galleries support
  • Office 2007 styling for controls included, like ComboBox, StatusBar etc.
  • KeyTips support
  • Windows Vista Glass Support
  • Predefined color schemes Blue, Silver, Black
  • Create unlimited custom color schemes based on single color and one of our predefined color tables
  • Ribbon popup menu support
  • Quick Access Toolbar (QAT) with customization
  • Excellent integration with WPF Routed Commands
  • Right-To-Left (RTL) fully supported
  • XBAP support, use it in your Click-Once XBAP applications

Continue

Professional Docking Control for WPF


Company: devcomponents.com

Wpf-Dock is world's first Windows Presentation Foundation docking control with Office 2007 style developed from ground up to take advantage of new presentation layer.

We designed Wpf-Dock with simplicity in mind. We reduced number of classes you need to get familiar with to use the control and we carefully evaluated each property and method that is exposed on the control. Advanced docking layout engine we developed gets out your way and allows you to create very complex docking layout easily.

Here is just partial list of Wpf-Dock features:

  • Fully featured docking including Document docking
  • Easy document and docking window switching using Ctrl+Tab keys
  • Diamond docking guides for easy docking
  • Intelligent animation for docking transitions
  • Auto-hide capability
  • Save and Restore docking layout easily
  • Office 2007 Blue, Silver, Black styling included
  • Create unlimited custom color schemes based on single color and one of our predefined color tables
  • Right-To-Left (RTL) fully supported
  • XBAP support, use it in your Click-Once XBAP applications

Continue