Posts

Showing posts from June 28, 2009

Creating an ASP.NET GridView Custom Field of type DropDownList

Image
Introduction Sometimes, you need to use a DropDownList in a GridView in a way to see the text of fields and save values in to your database. Here, we have extended the “ BoundField ” class and added features to create a column type of “ DropDownList ”. For example, in this picture, you can see two tables, Customer and Category . Suppose you need to edit the content of the Customer table with a GridView and select “Customer Category” through a “ DropDownList ”. You want to see the CategoryName in the grid but save CategoryID in to the database, like in this picture: Background You have two solutions: The first solution is to create a Template column of type DropDownList . The second solution is to create a new column type with the “ DropDownList ” editor and introduce an “Entity Name” for it. Here, we have extended the “ BoundField ” class and added features to create a column type of “ DropDownList ”. Using the code Now, you can use this column type easil

Model View Presenter

Image
Introduction and Goal In this article we will understand MVP, execute a sample project with MVP, implement the same using windows UI and then finally we will discuss about the differences between MVP and MVC. For past some days I have been writing and recording videos in design patterns, UML , FPA , Enterprise blocks and lot you can watch the videos at http://www.questpond.com You can download my 400 .NET FAQ EBook from http://www.questpond.com/SampleDotNetInterviewQuestionBook.zip Pre-requisite This article assumes you know MVC in case not you can read about the same at http://www.codeproject.com/KB/aspnet/3Musketeers.aspx The simple stock project The best ways to understand any architectural concept is by taking a small practical sample and then apply fundamentals on the same. So let’s first discuss a simple scenario and then let’s think how MVP fits in to the same. Below is a pictorial representation of a simple stock project. We can increase the stock value a

Create Composite Control using Ajax Toolkit Controls

Introduction Ajax Control Toolkit allows the developer to create Web applications that can update data on the Web page without a complete reload of the page, and contain many controls with very interesting features: popup panels, resizable controls, floating controls and others. Often you want a control with some features of some other controls, so you can achieve the goal of joining more controls in a single control as CompositeControl . Composite Controls are controls that combine multiple controls together to form a new reusable control. For example, I want to create a control container that makes resizable, collapsible, draggable all guest controls as IFrame or others. ResizableControlExtender , CollapsiblePanelextender , DragPanelExtender controls extend their own features to the Panel written on TargetControlID property so you can create a mix like this: See full detail: http://www.codeproject.com/KB/ajax/AjaxCompositePanel.aspx

Change File Date Attributes

Image
Introduction Have you ever found yourself in a situation where you wanted to change the attributes of a file such as the creation date, modified date or last accessed date. For one reason or another, sometimes you might just want to change the attributes, and since Windows does not offer an easy way to do so, I wrote a small easy-to-use program to change the date of a file. Using the Program After extracting and executing the program, click open and load the file for which you want to change the attributes. After you open the file, you will see its path in the textbox in the bottom of the program. Now all you have to do is just click on the checkbox that you wish to edit, and select a new time and date. Click Save and the new attributes will be saved into the file. The file attributes will look like the following: Using the Code I will explain just the functions required to change the date attributes. First we add the IO library: See full detail: http://www.codepro

Add Group Collapse Behavior on a Listview Control

Image
Introduction ListView control is an important but complex control in the WinForm environment. Group behavior is added into this control, but unfortunately, we can't collapse or expand the group. I'll show how to use some simple code to add collapse/expand behavior on the ListView control. This is a sample image on Windows Vista and Windows Server 2008: Default group without Collapse/Expand behavior Group with Collapse/Expand behavior Using the Code See full detail: http://www.codeproject.com/KB/list/ListviewGroupCollapse.aspx

Beginner's Guide To View State

Image
Introduction First of all I want to thank Sean Ewington for his great initiative to write Beginner's Walk for Web Development article. I have decided to write some articles on state management There are a few article on Code project on State Management, basically on Session, Caching, Cookies, etc. Though all are very good article, still I have planned for write some article on state management. and I believe that should definitely helps to all the Beginners. And I have organized the content in a way that it would be helpful to not only beginners also to advance user also. In this article, I will cover the fundamentals of State Management and Details of View State. What is state management? Web is Stateless . It means a new instance of the web page class is re-created each time the page is posted to the server. As we all know HTTP is a stateless protocol, its can't holds the client information on page. As for example , if we enter a text and client on submit bu

Dynamic LINQ To Entities Queries Using WCF/WPF demo code

Image
Introduction It has been a while since I have undertaken a large article, so I thought it was about time I corrected that, and wrote a fairly meaty article. This article represents this meat. So I suppose I should start by stating what it is this article will cover. Well it's going to cover quite a lot actually. The basic idea is that there is a SQL Server database somewhere that has the Northwind database installed, and that we will be using an ORM to obtain data from this database using a WCF service. The WCF itself will be hosted inside a Windows service which will be installed via a customer installer. In order to interact with this Windows hosted WCF service we will be using a WPF client application. The WPF client application will allow the user to obtain particular entities (Customers only as I would have been writing this article for ever to allow for everything) to be queried using a custom query builder that will then be used to send to the Windows hosted W

GMarkupLabel - A C# Windows Forms control to display XML-formatted text

Image
Introduction I believe that almost every .NET developer, assigned a task to display text, has experienced hard times with precise text measuring and drawing. The System.Drawing.Graphics MeasureString and DrawString methods have several limitations, worst of all being not so accurate measuring and positioning of the desired text. Since .NET 2.0, Microsoft has introduced the TextRenderer class that provides more precise text manipulation, but also has its cons – may render only with solid colors, no transparency, etc. Neither of the above described approaches gives you the opportunity to have mixed font texts, extended paragraph layouts like justify, or additional text effects like stroke or shadow. All that said, I thought it would be a nice exercise to create a custom text rendering solution that both solves the standard problems and also adds some nice features. Having solid experience with GDI+ and Windows Forms (I was a GUI developer for over 4 years), I started

Introduction This article provides a simple example of using jQuery along with the jQuery tablesorter and tablesorter.pager plug-ins to provide sorti

I searched long and hard for this solution on the net but to no avail but got hints on how to do it on a few sites but the problem was I was that type of programmer who avoided using the database for anything but storage. I preferred my database as a reservoir of data no thinking/intelligence apart from the auto generated integers offered by the DBMS until a client asked for a prefixed six digit auto generated sequential code to identify each record in the system . This became my agony for weeks, not that I was clueless but I had ideas (quick escape) a solution for that moment as I think of a more permanent one. To cut the long story short all those ideas failed but the one which worked is this one (using a trigger). I know many of you will say y triggers not just a function to check the last number(CHKLST) in the database and then just add 1 to that number, this is y, in a distributed environment there is a chance that the function(CHKLST) which checks the last value/