Bind data to a drop down list in a ASPX page

If you have a drop down list control that you need to populate on page load and you want todo it through code, here is how:

#1: DropDownList1.DataSource = obj.PopulatVehicleNumber();
#2: DropDownList1.DataTextField = “Vehicleno”;
#3: DropDownList1.DataValueField = “Vehicleno”;
#4: DropDownList1.DataBind();

Explanation:

In #1 I have created an object of a class that has the data base connectivity implementation. What #1 does is to fetch you a table that you assign as a data source to the drop down list control.
#2 defines the text field for the drop down list. This is the values that the users will see and select from. The DataTextField is a property of the drop down list control. This property specifies which field from the DataSource is to be bound to the Text property of each item in the control.

#3 defines the value field for the text mentioned in #2. This will be the value that you will typically use to make some decisions on. For example, supposing a user selects a text “United States” from a Country drop down. You may decide to assign this text a id of say ‘0001’ as the value. You may then take logical decisions based on this field.

#4 calls the DataBind() method to bind the data to the drop down list control. The control remains empty until data binding occurs. This method used to bind data from a data source (eg. database) to a server control.

That’s it!!

Advertisement

Configuring SQL Server 2008 server authentication modes

SQL Server 2008 supports 2 modes of authentication:

  1. Windows Authentication mode and
  2. SQL Server and Windows Authentication Mode

You can view the current authentication mode that the server is using the following steps:

  1. Connect to the Server using SQL Server Management Studio.
  2. Right click on the server name (the root of the tree that is displayed in the object viewer)
  3. On the properties window, select “Security”
  4. Under “Server Authentication” section, you will see the current authentication mode of the server. Change the authentication mode here if required.

You have to restart the server. If SQL Agent is running this also will require a restart.
You will need SQL Server sysadmin privilege to make any changes to the Authentication mechanism of the server. This decision should be taken after thorough evaluation of the system and various security aspects involved.