Displaying Paging In ASP.Net
Posted in .Net, ASP.Net, C#, Uncategorized on April 22, 2008 | No Comments »
Posted in .Net, ASP.Net, C#, Uncategorized on April 22, 2008 | No Comments »
Posted in C#, Uncategorized on December 5, 2007 | No Comments »
The goal here is to take advantage of C# 2.0 features as generics and create a reusable data layer capable of calling any stored procedure, with any sets of parameters and returning different sets of results.
The DataUtility class:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
///
/// Summary description for DataUtility
///
namespace Data
{
[...]
Posted in .Net, ASP.Net, C#, Uncategorized on December 5, 2007 | No Comments »
Sometimes, there is a need to post a form from one page to another without any UI element. This is how to do it programmatically:
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(“FormElementName=” + formElementValue);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(http://somesite/somepage);
myRequest.Method = “POST”;
myRequest.ContentType = “application/x-www-form-urlencoded”;
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
Posted in .Net, ASP.Net, C#, HTML, JavaScript, Uncategorized on October 25, 2007 | No Comments »
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:ListBox ID=”LBSource” SelectionMode=”Multiple” runat=”server”>
<asp:ListItem Text=”Item1″ Value=”vItem1″></asp:ListItem>
<asp:ListItem Text=”Item2″ Value=”vItem2″></asp:ListItem>
<asp:ListItem Text=”Item3″ Value=”vItem3″></asp:ListItem>
<asp:ListItem Text=”Item4″ Value=”vItem4″></asp:ListItem>
<asp:ListItem Text=”Item5″ Value=”vItem5″></asp:ListItem>
</asp:ListBox>
<input type=”button” value=”Add” onclick=”moveItems(’<%= LBSource.ClientID %>‘, ‘<%= LBDestination.ClientID %>‘)” />
<input type=”button” value=”Remove” onclick=”moveItems(’<%= LBDestination.ClientID %>‘, ‘<%= LBSource.ClientID %>‘)” />
<asp:ListBox [...]
Posted in .Net, C# on April 12, 2007 | No Comments »
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
// Check if the target directory exists, if not, create it.
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
// Copy each file into it’s new directory.
foreach (FileInfo fi in source.GetFiles())
{
Console.WriteLine(@”Copying {0}\{1}”, target.FullName, fi.Name);
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
}
// Copy each subdirectory using recursion.
[...]
Posted in .Net, C# on January 9, 2007 | No Comments »
To disable a compilation error in C#, you only need to put this code just before the method declaration:
#pragma warning disable xxxx
Where xxxx is the error code from compilation like 0429 for example.
Posted in .Net, C# on October 18, 2006 | No Comments »
Class Modifiers
The class is one of the two basic encapsulation constructs in C# (the other being the struct). Every executable statement must be placed inside a class or struct. Classes define reference types that are the basic building blocks of C# programs, and they are the architectural blueprint for the “objects” in OOP.
A class can [...]
Posted in C#, Uncategorized on September 29, 2006 | No Comments »
C# Coding Standards here
Posted in C#, Uncategorized on September 29, 2006 | No Comments »
This class can instantiate any class, from any namespace, with any kind and amount of parameters.
You only need to have in the instantiated class constructor, the code you need to execute without having to do a reflection on methods of the class and call them in a second step:
public class Factory
{
public Factory(object[] args, string [...]
Posted in C#, XML, XSLT on September 28, 2006 | No Comments »
Many things cannot be done in xslt directly due to a lack of manipulation functions. In order to cure that, Microsoft has provided a way to include c# code directly in xslt. Here’s an example:
<?xml version=“1.0“ encoding=“utf-8“ ?>
<xsl:stylesheet version=“1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform“ xmlns:msxsl=“urn:schemas-microsoft-com:xslt“ xmlns:ClassNameHere=“dummy namespace here“>
<msxsl:script language=“C#“ implements-prefix=“ClassNameHere“>
<![CDATA[
public string MethodName(/* some parameters here*/)
[...]