ASP.NET(vb.net) & BulletedList in DataBinding - asp:BulletedList : How to use BulletedList control and display BulletedList from data binding or bind the control to a data source.
ShotDev Focus:
- ASP.NET(vb.net) & BulletedList in DataBinding
Example
BulletedListDataBind.aspx
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OleDb"%> <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) IF Not Page.IsPostBack() Then BulletedListDataTable() BulletedListDataTableRows() BulletedListSortedList() BulletedListAddInsertItem() End IF End Sub '*** BulletedList & DataTable ***' Function BulletedListDataTable() Dim objConn As OleDbConnection Dim dtAdapter As OleDbDataAdapter Dim dt As New DataTable Dim strConnString As String strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _ Server.MapPath("shotdev/mydatabase.mdb")&";" objConn = New OleDbConnection(strConnString) objConn.Open() Dim strSQL As String strSQL = "SELECT * FROM country" dtAdapter = New OleDbDataAdapter(strSQL, objConn) dtAdapter.Fill(dt) dtAdapter = Nothing objConn.Close() objConn = Nothing '*** BulletedList ***' With Me.myBuList1 .DataSource = dt .DataTextField = "CountryName" .DataValueField = "CountryCode" .DataBind() End With End Function '*** BulletedList & TableRows ***' Sub BulletedListDataTableRows() Dim dt As New DataTable Dim dr As DataRow '*** Column ***' dt.Columns.Add("Sex") dt.Columns.Add("SexDesc") '*** Rows ***' dr = dt.NewRow dr("Sex") = "M" dr("SexDesc") = "Man" dt.Rows.Add(dr) '*** Rows ***' dr = dt.NewRow dr("Sex") = "W" dr("SexDesc") = "Woman" dt.Rows.Add(dr) '*** BulletedList ***' With Me.myBuList2 .DataSource = dt .DataTextField = "SexDesc" .DataValueField = "Sex" .DataBind() End With End Sub '*** BulletedList & SortedList ***' Sub BulletedListSortedList() Dim mySortedList AS New SortedList mySortedList.Add("M","Man") mySortedList.Add("W","Woman") '*** BulletedList ***' With Me.myBuList3 .DataSource = mySortedList .DataTextField = "Value" .DataValueField = "Key" .DataBind() End With End Sub '*** Add/Insert Items ***' Sub BulletedListAddInsertItem() Dim mySortedList AS New SortedList mySortedList.Add("M","Man") mySortedList.Add("W","Woman") '*** BulletedList ***' With Me.myBuList4 .DataSource = mySortedList .DataTextField = "Value" .DataValueField = "Key" .DataBind() End With '*** Add & Insert New Item ***' Dim strText,strValue As String '*** Insert Item ***' strText = "" strValue = "" Dim InsertItem As New ListItem(strText, strValue) myBuList4.Items.Insert(0, InsertItem) '*** Add Items ***' strText = "Guy" strValue = "G" Dim AddItem As New ListItem(strText, strValue) myBuList4.Items.Add(AddItem) End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <asp:BulletedList id="myBuList1" runat="server"></asp:BulletedList><hr /> <asp:BulletedList id="myBuList2" runat="server"></asp:BulletedList><hr /> <asp:BulletedList id="myBuList3" runat="server"></asp:BulletedList><hr /> <asp:BulletedList id="myBuList4" runat="server"></asp:BulletedList> </form> </body> </html>
Screenshot