GridView drop-down list record update:

Found this code on msdn library and use it all the time. Code is pretty straight forward and easy to implement and customizable. Have fun using it.

<asp:TemplateField SortExpression="CategoryName" 
HeaderText="CategoryName">
   <EditItemTemplate>
        <asp:DropDownList ID="DropDownList1" Runat="server" 
          DataSourceID="categoryDataSource"
            DataTextField="CategoryName" DataValueField="CategoryID" 
            SelectedValue='<%# Bind("CategoryID") %>'>
        </asp:DropDownList>        
   </EditItemTemplate>
   <ItemTemplate>
       <asp:Label Runat="server" Text='<%# Bind("CategoryName") %>' 
          ID="Label1"></asp:Label>
   </ItemTemplate>
</asp:TemplateField>

For more related code read here…

Classic ASP – Date and time formating

Code

<script type="text/vbscript">
   document.write(DateAdd("yyyy",1,"31-Jan-10") & "
") document.write(DateAdd("q",1,"31-Jan-10") & "
") document.write(DateAdd("m",1,"31-Jan-10") & "
") document.write(DateAdd("y",1,"31-Jan-10") & "
") document.write(DateAdd("d",1,"31-Jan-10") & "
") document.write(DateAdd("w",1,"31-Jan-10") & "
") document.write(DateAdd("ww",1,"31-Jan-10") & "
") document.write(DateAdd("h",1,"31-Jan-10 08:50:00") & "
") document.write(DateAdd("n",1,"31-Jan-10 08:50:00") & "
") document.write(DateAdd("s",1,"31-Jan-10 08:50:00") & "
") </script>
Output

1/31/2011
4/30/2010
2/28/2010
2/1/2010
2/1/2010
2/1/2010
2/7/2010
1/31/2010 9:50:00 AM
1/31/2010 8:51:00 AM
1/31/2010 8:50:01 AM 

Text-box autocomplete

The code is initial designed by Mircho Mirev [ momche.net ]. I’ve enhanced this script so instead of array of static data the text-box auto-complete uses database back end.

Default.asp

<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”65001″%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<title>Intellisense Example</title>
<SCRIPT language=”JavaScript” src=”moautocomplete.js”></SCRIPT>
</head>
<body style=”font-family: Verdana, Geneva, sans-serif; font-size: 12px;”>
<div style=”padding-top: 200px; font-family: Verdana; font-size: 12px;”>
<%
‘ Set up one data series for each category of product
Set objConn = Server.CreateObject(“ADODB.Connection”)
dbPath = Server.MapPath(“Intellisense.accdb”)
objConn.Open “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” & dbPath, “”, “”
SET objRS = Server.CreateObject(“ADODB.RecordSet”)
objRS.Open “SELECT * FROM Applicants ORDER BY sProgram”,objConn,1,2
%>
<form method=”get”>
<b>Intellisense/autocomplete textbox</b> with db backend<br /><br />

Scholarship Program: <INPUT id=”program” type=”text” name=”program” autocomplete=”list:
<%
While Not objRS.EOF
Response.Write(objRS(“sProgram”)&”|”)
objRS.MoveNext
WEND
%>”><input type=”submit” id=”submit” value=”GO!”>
</form>
</div>
</body>
</html>

Moautocomplete.js

var cAutocomplete =
{
sDescription : ‘autcomplete class’
}

cAutocomplete.complete = function( hEvent )
{
if( hEvent == null )
{
var hEvent = window.hEvent
}

var hElement = ( hEvent.srcElement ) ? hEvent.srcElement : hEvent.originalTarget

var sAA = hElement.getAttribute( ‘autocomplete’ ).toString()
if( sAA.indexOf( ‘array:’ ) >= 0 )
{
hArr = eval( sAA.substring( 6 ) )
}
else if(  sAA.indexOf( ‘list:’ ) >= 0 )
{
hArr = sAA.substring( 5 ).split( ‘|’ )
}

if( hEvent.keyCode == 16 )
{
return
}
var sVal = hElement.value.toLowerCase()
if( hEvent.keyCode == 8 )
{
sVal = sVal.substring( 0, sVal.length – 1 )
}
if( sVal.length < 1 )
{
return
}
for( var nI = 0; nI < hArr.length; nI++ )
{
sMonth = hArr[ nI ]
nIdx = sMonth.toLowerCase().indexOf( sVal, 0 )
if( nIdx == 0 && sMonth.length > sVal.length )
{
hElement.value = hArr[ nI ]
if( hElement.createTextRange )
{
hRange = hElement.createTextRange()
hRange.findText( hArr[ nI ].substr( sVal.length ) )
hRange.select()
}
else
{
hElement.setSelectionRange( sVal.length, sMonth.length )
}
return
}
}
}

cAutocomplete.init = function()
{
var nI = 0
var aInputs = document.getElementsByTagName( ‘INPUT’ )
for( var nI = 0; nI < aInputs.length; nI ++ )
{
if( aInputs[ nI ].type.toLowerCase() == ‘text’ )
{
var sLangAtt = aInputs[ nI ].getAttribute( ‘autocomplete’ )
if( sLangAtt )
{
if( document.attachEvent )
{
aInputs[ nI ].attachEvent( ‘onkeyup’, cAutocomplete.complete )
}
else if( document.addEventListener )
{
aInputs[ nI ].addEventListener( ‘keyup’, cAutocomplete.complete, false )
}
}
}
}
}

if( window.attachEvent )
{
window.attachEvent( ‘onload’, cAutocomplete.init )
}
else if( window.addEventListener )
{
window.addEventListener( ‘load’, cAutocomplete.init, false )
}