Category: Knowledge Base

Remove selected items from a ListBox

Suppose you have a ListBox named listBox1. If you want to remove the selected item from it, use the Items.Remove() method, and pass as an argument the SelectedItem property: listBox1.Items.Remove(listBox1.SelectedItem); However if the ListBox has the SelectionMode set to MultiExtended and you want to remove all the selected items, use the following code: while(lstKeys.SelectedItems.Count > 0){lstKeys.Items.Remove(lstKeys.SelectedItem);}

What are the special directories in ASP.NET 2.0

When creating a new ASP.NET 2.0 website in Visual Studio 2005 you may notice the App_Data and/or the App_Browsers directories. App_Data is a directory reserved for databases and database related files, such as .mdb (Microsoft Access Database), .mdf (Microsoft SQL Express) or XML files. The main advantage of using this folder over any other folder is the preconfigured access permissions, […]

What is the difference between the int and Int32 datatype, or String and string (lowercase)?

Int32 is the System.Int32 class, while int is an alias for System.Int32.The same applies for String (uppercase S) which is System.String, while string (lowercase S) is an alias for System.String.So basically int is the same thing as Int32, and string is the same thing as Int32. It’s down to user’s preference which one to use but most prefer to use int and string as they are easier to type and more familiar among C++ programmers.

In .NET 2.0 accessing the values stored in web.config through System.Configuration.ConfigurationSettings.AppSettings doesn’t seem to work anymore

In .NET 2.0 System.Configuration.ConfigurationSettings.AppSettings has been changed to System.Configuration.ConfigurationManager.AppSettings. Also youneed to add a reference to System.Configuration.dll.Here’s an example of accessing the SomeString value from the web.config file, in .NET 2.0: System.Configuration.ConfigurationManager.AppSettings[“SomeString”];

How do I generate a random number within a range?

Using .NET you can easily generate a random number withing a range, by using the Random class. In the following example a random number between 1 and 69 will be generated: System.Random RandNum = new System.Random();int MyRandomNumber = RandNum.Next(69); To generate a random number between 1986 and 2005 you would use: System.Random RandNum = new System.Random();int MyRandomNumber = RandNum.Next(1986, […]

Back To Top