These are the basic data types in C# and their range: Keyword Class Range bool System.Boolean true and false byte System.Byte 0 to 255 sbyte System.SByte -128 to 127 short System.Int16 -32768 to 32767 ushort System.Uint16 0 to 65535 int System.Int32 -2,147,483,648 to 2,147,483,647 uint System.UInt32 0 to 4,294,967,295 long System.Int64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 ulong […]
ASP.NET DropDownList of US states
Below there is a list of states inside United States, each being a ListItem inside an ASP.NET DropDownList:
How do I create multiple entry points and specify which one to use?
How do I create multiple entry points and specify which one to use?To create multiple entry points you simply add multiple classes, each with a static Main function: using System;namespace MultipleEntryPoints{ class Class1 { class Point1 { [STAThread] static void Main(string[] args) { Console.WriteLine(“This is point 1”); } } class Point2 { [STAThread] static void Main(string[] args) { Console.WriteLine(“This is point 2”); } } class Point3 { [STAThread] static void Main(string[] args) { Console.WriteLine(“This is […]
How to select a random value from an array
To select a random value from an array (in the example below, an array of strings) we first generate a random number between 0 and the length of the array (which is also the last value in the array). // Initialize the string arraystring[] strStrings = { “Random string”, “Another random value from the array”, “Randomly selected index” };// […]
How to reset the identity column of a SQL table
To reset the value of the identity column in a Microsoft SQL table run the below query: DBCC CHECKIDENT (TableName, RESEED, 0) You will need to change TableName to the name of the table you wish to reset. This query will reset the identity column to 0, meaning the next row will have the identity 1. You can […]
How to check if Windows XP SP2 is installed
The easiest way to check the version of Windows on which your .NET application is running, is to use the following line: The above line should return something similar to “Microsoft Windows NT 5.1.2600 Service Pack 2” on a system running Windows XP SP2. However, if it does not, an alternative and more precise way […]
Binding a Repeater control to a jagged array
Binding the Repeater in the code-behind is done just like with any other binding operation. Suppose we have a jagged array named myJagged (which we didn’t initialize with values in this example) and a Repeater named myRepeater: // Initialize the string arraystring[][] myJagged; // Remember to initialize the array with valuesmyRepeater.DataSource = GroupList;myRepeater.DataBind(); While binding the array to the repeater is done the […]
Adding an item in a DropDownList at a certain position
In ASP.NET when you add a new item using a line such as the one below, and there are items already in the DropDownList, you will notice that this one is added at the bottom of the list. ddlMyList.Items.Add(“The Swan”);Sometimes you will be able to move this line in your code relative to the other […]
A disabled TextBox or similar control does not maintain its value through PostBack
It is normal behaviour for an ASP.NET TextBox and other controls similar to it to lose their value through PostBack when they have the Disabled attribute set to True. To work around this behaviour, you can either use a Hidden type of field if you don’t want the user to see the value of the field in the page, or […]
Can I use my existing DLLs with ASP.NET?
If you have existing DLLs or COM objects developed and compiled in different languages such as Visual Basic, the good news is that you can use them in your ASP.NET web application just like any other DLLs. In Visual Studio, all you need to do is add a reference to the DLL via the Solution […]