Posts

Showing posts from December, 2012

SQL Server Query Use Of STUFF

Image
Without Use Of Stuff Function With Use Of Stuff Function

Use Of PATINDEX In SQL SERVER

Image

Use Of CharIndex In Sql Server

Image

Delete Confirmation for Delete ButtonField, TemplateField and CommandField in a GridView in ASP.NET

Introduction: This article explains how to add delete confirmation for ButtonField, CommandField and TemplateField columns in a GridView. In this example, I am using a GridView and delete buttons to just hide the row to keep the demo simple. Markup: < html   xmlns = "http://www.w3.org/1999/xhtml" > < head   runat = "server" >      < title ></ title > </ head > < body >      < form   id = "form1"   runat = "server" >      < asp : GridView   ID = "GridView1"   runat = "server"   Font-Names = "Tahoma"   Font-Size = "Small"          CellPadding = "4"   BorderColor = "#507CD1"   BorderStyle = "Solid"   AutoGenerateColumns = "false"          ForeColor = "#333333"   GridLines = "None"   OnRowDataBound = "GridView1_RowDataBound"          OnRowDeleting = "GridView1_RowDelet

Sorting GridView with LINQ and adding Sort Image URL in ASP.NET

Introduction: This article explains how to sort GridView without getting sorted resultset from database thereby saving a database hit. Example in this article uses a GridView with three columns. Background: Showing images to denote the column sorted and sort direction helps user differentiate sorted column from others. Images can be added to header in different ways. One way is keeping a Panel in HeaderTemplate and adding Images dynamically. Another simple way is inserting image HTML in Header Text along with Header Text in Data Binding Event. Markup: < form   id = "form1"   runat = "server" > < asp : ScriptManager   ID = "sc"   runat = "server"   EnablePartialRendering = "true" > </ asp : ScriptManager > < asp : UpdatePanel   ID = "up"   runat = "server" >      < ContentTemplate >          < asp : GridView   ID = "GridView1"   runat = "server&

Loading DropDownList from Enumeration in ASP.NET

Introduction: This article shows how to load DropDownList from Enumeration using extension methods. Example in this demo loads DropDownlists from DayOfWeek and SpecialFolders Enumerations respectively. Background: Extension Methods often helps extend base functionality of an object by refactoring code. Unfortunately, Classes such as System.Enum, System.Object cannot be extended like a string or integer type. There are different ways to convert Enumeration to a List but I prefer using Enum GetNames and GetValues methods to make a list. Markup: html > < head   runat = "server" >      < title ></ title > </ head > < body >      < form   id = "form1"   runat = "server" >      < table   style = " font-family :  Tahoma ;  font-size :  small ;" >          < tr >              < td >                 Day:              </ td >              < td >         

Selecting/Deselecting all CheckBoxes inside a ListView In ASP.NET

Introduction: This articles shows how to toggle checkboxes selection in a ListView using Javascript. Example in this article shows a ListView populated with random records with SelectAll functionality Background:   Often we are required to make one or multiple selection when different options are presented in a databound control such as GridView, Repeater, ListView so on. It is cumbersome to deselect each item individually when the selection has to be cleared. ListView Header can contain a checkbox to select/deselect items in all items of the ListView. Markup:    < html   xmlns = "http://www.w3.org/1999/xhtml" > < head   id = "Head1"   runat = "server" >      < title ></ title >      < script   type = "text/javascript" >          function  toggleCheckBoxes(source) {              var  listView = document.getElementById( ' <% =  ListView1.FindControl("table1").ClientID  %>

How to check all check boxes in listview?

Code : For i=1 to listview1.listitems.count Listview1.Listitems(i).Checked=True next

Remove Duplicate Chars From String

Remove Duplicate Chars From String CREATE FUNCTION dbo.REMOVE_DUPLICATE_INSTR ( @datalen_tocheck INT , @string VARCHAR ( 255 )) RETURNS VARCHAR ( 255 ) AS BEGIN DECLARE @str VARCHAR ( 255 ) DECLARE @count INT DECLARE @start INT DECLARE @result VARCHAR ( 255 ) DECLARE @end INT SET @start = 1 SET @end = @datalen_tocheck SET @count = @datalen_tocheck SET @str = @string WHILE ( @count <= 255 ) BEGIN IF ( @result IS NULL) BEGIN SET @result = '' END SET @result = @result + SUBSTRING ( @str , @start , @end ) SET @str = REPLACE ( @str , SUBSTRING ( @str , @start , @end ), '' ) SET @count = @count + @datalen_tocheck END RETURN @result END GO Usage: SET CONCAT_NULL_YIELDS_NULL OFF SELECT dbo.Remove_duplicate_instr (< CHAR length OF a duplicate SUBSTRING >,< string contain duplicate >) Example: To keep char set in a string unique and remove duplicate 3 char long string run this UDF as inline function. SET CONCAT_NULL