Creating Dropdown list control from Datasource

posted by Scudyen date: Thursday, May 22, 2008 category: ASP.NET

 

We will create a custom dropdown conrol using a datasource. This code provides us to fill a dropdrown list using a datasource.  This code also displays us ASP.NET is easier than classical ASP to generate custom controls.

Do not forget to modify database connection and your sql statement.

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script language="VB" runat="server">

 Sub Page_Load(Source as Object, E as EventArgs)

 Dim objCon As OleDBConnection
        objCon = New OleDBConnection("Provider=sqloledb;Data Source=LOCALHOST;Initial catalog=northwind;User Id=sa;Password=;")
 Dim ds as new DataSet
   Dim objAdapter As OleDBDataAdapter = New OleDBDataAdapter("Select * from categories order by categoryID desc", objCon)

 objAdapter.Fill(ds)

 catList.DataSource=ds.tables(0).DefaultView
 catList.DataValueField="categoryID"
 catList.DataTextField="categoryName"
 catList.DataBind()
 end sub


</script>
<html><body>

<form runat="server">
<asp:DropDownList id="catlist" runat="server"/>
</form>
</body></html>

Read More

Custom Search



Gazatem Technologies Active News Manager


page counter

Listed with 411asp.net Listed with 4aspin.com