At this point, this is not really much of a tutorial, other than to show you some of the neat things that can be done with ASP.Net.
The Book, Chapter and verse DropDownlists are set up with AutoPostBack=”True”, along with Subs triggered by the OnSelectedIndexChanged Event, so that whenever an item is chosen, it can trigger the event and not need to have a ‘Submit’ button to do it.
Past that, you will see that the display portions are done using a DataGrid and a DataList.
The Source Code for the User Control is shown below. Enjoy.
Source Code:
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.OleDB” %>
// <![CDATA[
Sub Page_Load(Source as Object, E as EventArgs)
if not Page.IsPostBack then
doData()
end if
End Sub
Sub doData()
Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
server.mappath("\data\bible.mdb") & ";"
Dim MySQL as string ="Select ID, name from books"
Dim MyConn as New OLEDBConnection(strConn)
Dim Cmd as New OleDBCommand(MySQL,MyConn)
MyConn.Open()
Mybooks.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Mybooks.DataBind()
Mybooks.items.insert(0,"")
End Sub
Sub dd1Books_SelectedIndexChanged(Source as Object, E as EventArgs)
txtSearch.text=""
doChapters
End Sub
Sub doChapters()
DGSearch.visible="False"
MyDataGrid.currentpageIndex=0
lblcount.text=MyDataGrid.currentpageindex & " - " & MyDataGrid.pagecount
Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
server.mappath("\data\bible.mdb") & ";"
Dim MySQL as string = "Select Distinct Chapter from chapters Where book = " & _
MyBooks.selecteditem.value
Dim MyConn as New OleDBConnection(strConn)
Dim Cmd as New OLEDBCommand(MySQL, MyConn)
MyConn.Open()
MyChapters.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
MyChapters.DataBind()
MyChapters.items.insert(0," ")
MyChapters.visible="True"
lblChapters.visible="True"
MyVerses.visible="false"
lblVerses.visible="false"
MyDataList.visible="false"
MyDataGrid.visible="false"
lblHdr.visible="false"
End Sub
Sub ddlChapters_SelectedIndexChanged(Source as Object, E as EventArgs)
doVerses
MyDataGrid.visible="True"
DGSearch.visible="False"
FillGrid
End Sub
Sub doVerses()
if MyVerses.visible="True" then
MyDatalist.visible="false"
else
MyVerses.visible="True"
lblVerses.visible="True"
end if
Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
server.mappath("\data\bible.mdb") & ";"
Dim MySQL as string = "Select distinct verse from chapters Where book = " & _
MyBooks.selectedItem.value & " and " & _
"chapter=" & MyChapters.selectedItem.text
Dim MyConn as New OleDBConnection(strConn)
Dim Cmd as New OLEDBCommand(MySQL, MyConn)
MyConn.Open()
MyVerses.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
MyVerses.DataBind()
MyVerses.items.insert(0," ")
End Sub
Sub ddlVerses_SelectedIndexChanged(Source as Object, E as EventArgs)
doText
End Sub
Sub doText()
Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("\data\bible.mdb") & ";"
Dim MySQL as string = "Select book, chapter, verse, versetext from chapters Where " & _
"book = " & MyBooks.selectedItem.value & " and chapter=" & MyChapters.selectedItem.text & " and " & _
"verse=" & MyVerses.selecteditem.text
Dim MyConn as New OleDBConnection(strConn)
Dim Cmd as New OLEDBCommand(MySQL, MyConn)
MyConn.Open()
MyDataList.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
MyDataList.DataBind()
MyDatalist.visible="True"
FillGrid
lblHdr.text=MyBooks.selecteditem.text
End Sub
Sub FillGrid()
DGSearch.visible="false"
MyDataGrid.visible="true"
Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
server.mappath("\data\Bible.mdb") & ";"
Dim MySQL as string = "Select books.name, chapters.chapter, chapters.verse, chapters.versetext from " & _
"chapters INNER JOIN books ON books.ID= chapters.book where Chapters.Book=" & _
MyBooks.selecteditem.value & " and " & _
"Chapter = " & MyChapters.selecteditem.text & " order by verse"
Dim MyConn as New OleDBConnection(strConn)
Dim ds as DataSet=New DataSet()
Dim Cmd as New OleDBDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"chapters")
MyDataGrid.Datasource=ds.Tables("chapters").DefaultView
With MyDataGrid
Try
.DataBind()
Catch
.currentpageindex=0
finally
.databind()
End Try
end with
lblHdr.visible="True"
lblHdr.Text="Book of " & MyBooks.selecteditem.text
lblcount.text=MyDataGrid.currentpageindex & " - " & MyDataGrid.pagecount
End Sub
Sub doSearch(Source As Object, E As EventArgs)
dgSearch.currentpageindex=0
getData
End Sub
Sub getData()
Dim MySQL as String
lblHdr.Text="Text Searched For : " & txtSearch.text
lblHdr.visible="true"
DGSearch.visible="True"
MyDataGrid.visible="false"
Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
server.mappath("\data\bible.mdb") & ";"
if NewTestament.Checked "True" then
MySQL = "Select books.ID, books.name, chapters.book, chapters.chapter, chapters.verse, chapters.versetext " & _
"from chapters INNER JOIN books ON books.ID= chapters.book Where " & _
"versetext Like '%" & txtSearch.text & "%' Order by Chapters.book,Chapters.Chapter, Chapters.Verse"
else
MySQL = "Select books.ID, books.name, chapters.book, chapters.chapter, chapters.verse, chapters.versetext " & _
"from chapters INNER JOIN books ON books.ID= chapters.book Where versetext Like '%" _
& txtSearch.text & "%' And Books.id > 39 Order by Chapters.book,Chapters.Chapter, Chapters.Verse"
End If
Dim MyConn as New OleDBConnection(strConn)
Dim ds as DataSet=New DataSet()
Dim Cmd as New OleDBDataAdapter(MySQL,MyConn)
Cmd.Fill(ds, "chapters")
MyDataList.visible="false"
dgSearch.Datasource=ds.Tables("chapters").DefaultView
With DGSearch
Try
.DataBind()
Catch
.currentpageindex=0
finally
.databind()
End Try
end with
lblcount.text=dgsearch.currentpageindex & " - " & dgsearch.pagecount
End Sub
Sub Change_Search(sender As Object, e As DataGridPageChangedEventArgs)
DGSearch.CurrentPageIndex = e.NewPageIndex
getData
End Sub
Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
FillGrid
End Sub
// ]]>
<!–
–>