Category Archives: Code Snippets

Code Snippets ASP.Net

Concatenate data fields as binding expression

Concatenate data fields as binding expression:

<asp:label id="Label1" runat="server" 
     text='<%# String.Format("{0}, {1}", Eval("ContactLastName"), Eval("ContactFirstName")) %>'>
</asp:label> 

how to implemented mailto in Hyperlink asp control inside the gridview:

<asp:HyperLink id="hl1" runat="server" 
   NavigateUrl='<%# Eval("Email" , "mailto:{0}") %>'
   Text='<%# Eval("Email") %>'>
</asp:HyperLink>
Code Snippets

Redirect Domain

php

 <?php
  header('HTTP/1.1 301 Moved Permanently');
  header('Location: http://www.sitedeexemplo.com');
?>

.htaccess

Redirect 301 / http://www.sitedeexemplo.com 

HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Redireccionamento</title>
<meta http-equiv="refresh" content="1; url=http://www.sitedeexemplo.com" />
</head>
<body>
</body>
</html> 

Javascript

<script type="text/javascript">
<!--
window.location = "http://www.sitesample.pt/dir"
//-->
</script>
Code Snippets .NET

Programmatically set the selected menu item in the Menu control

Mnu1.Items(1).Selected = True
Mnu1.FindItem("Nutrients").Selected = True
mnu1.Items(indexToSelect).Selected = True
MenuItem mi = this.Menu1.FindItem("Home");
 mi.Selected = true;
this.Menu1.Items[0].Selected = true;
Code Snippets .NET VB

Get First and last word from sentence

        Dim Nome As String = "Carlos Galhano"
        Dim firstword As String = Nome.Substring(0, Nome.IndexOf(" "))
        Dim lastWord As String = Nome.Substring(Nome.LastIndexOf(" "c) + 1)
        Response.Write("first: " & firstword & " Last: " & lastWord)
Code Snippets .NET ASP.Net 2.0

Pass Array via Query String

http://galhano.com/?var=1&var=2&var=3&var=4

vb sample:

  Dim arr = Request.QueryString("var").Split(",")
  For Each s In arr
    Response.Write("<br />var:" & var)
  Next
Code Snippets ASP.Net

Measure a function’s performance

Imports System.Diagnostics


Dim sw As New Stopwatch()
sw.Start()
' Do the work here
sw.Stop()
Console.WriteLine("Elapsed time: {0}", sw.Elapsed.TotalMilliseconds)

Code Snippets ASP.Net ASP.Net 2.0

Add value for dropdown list in asp.net


ListItem li =new ListItem();
 li.value="PT";
 li.Text="Portugal";
 dropdownlist1.Items.Add(li);

or


dropCategory.Items.Add( New ListItem( "Portugal", "PT" ) )

Code Snippets .NET ASP.Net

Set Calendar Extender’s SelectedDate=”<%=DateTime%>”

&lt;asp:TextBox ID=&quot;txtDate&quot; runat=&quot;server&quot; &gt;&lt;/asp:TextBox&gt;
&lt;cc1:CalendarExtender ID=&quot;CalendarExtender1&quot; runat=&quot;server&quot; TargetControlID=&quot;txtDate&quot; Format=&quot;MM/dd/yyyy&quot; OnClientShowing=&quot;showDate&quot; &gt; &lt;/cc1:CalendarExtender&gt;
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
function showDate(sender,args)
{
if(sender._textbox.get_element().value == &quot;&quot;)
{
var todayDate = new Date();
sender._selectedDate = todayDate;
}
}
&lt;/script&gt;
Code Snippets wordpress

Enabling Pretty Permalinks in WordPress

This walkthrough describes how to enable “Pretty Permalinks” for blog posts in the WordPress blog engine that is installed on IIS 7 and above. Typically, without URL rewriting functionality on a Web server, WordPress users must use “Almost Pretty” URLs, for example, http://contoso.com/index.php/yyyy/mm/dd/post-name/. By using the URL Rewrite module, you can use “Pretty Permalinks,” for example, http://example.com/year/month/day/post-name/, for WordPress blogs that are hosted on IIS.
Prerequisites

This walkthrough requires the following prerequisites:

IIS 7 or above with FastCGI and PHP installed. If you need to install PHP, follow the instructions in this article.
WordPress installed. If you need to install WordPress, follow the instructions in this article or use the instructions from the official WordPress site.
URL Rewrite installed.

Note that for the purposes of this walkthrough it is assumed that WordPress is installed in a Web site root directory. If WordPress is installed in a subdirectory, then the rewrite rules that are used in this walkthrough should be included in the Web.config file that is located within the same subdirectory where the WordPress files are.

read more »

Code Snippets Databases MySQL SQL

mysql ‘Proper case’ formating a column?

How to do something like:

Proper(“GALHANO.COM”) = “Galhano.com”

there’s no builtin function to do this but we combine CONCAT and SUBSTRING:

CONCAT(UCASE(SUBSTRING(`fieldName`, 1, 1)),LOWER(SUBSTRING(`fieldName`, 2)))