ASP.NET Table Searching

 
Rate Our Program
Excellent!
Very Good
Good
Fair
Poor

Introduction


This is a very quick time application built using Microsoft ASP.NET. Its basic purpose is to show the power and Rapid Application Development features in ASP.NET.

Searching and record listing is a very common task in dynamic website development. In asp it can be done using html tables and looping with help of "for-next" or "while-wend" loops using vbscript.

Code Example of showing grid record in ASP 3.0



<% dim rs
dim cn
dim msg

set cn = server.CreateObject("Adodb.Connection")
set rs = server.CreateObject("Adodb.Recordset")
cn.Open "Provider=Microsoft.Jet.oledb.4.0; Data Source=C:\Inetpub\wwwroot\biblio\db\biblio.mdb"
rs.open "Select * From rec", cn%>
<p>
<%
response.Write(msg)
if not rs.EOF then
%>
</p>
<form name="form1" method="post" action="">
<table width="44%" border=1 cellpadding=1 cellspacing=1 bordercolor="#000000">
<tr bgcolor="#CCCCCC">
<td width="4%">&nbsp; </td>
<td width="96%"><strong>Name</strong></td>
</tr>
<%while not rs.EOF
n = n + 1
%>
<tr>
<td width="4%"> <input id=checkbox1 type=checkbox name=d<%=n%> value="<%=rs.Fields("id")%>">
</td>
<td><a href="new.asp?id=<%=rs.Fields("ID")%>"><%=rs.Fields("Name")%></a></td>
</tr>
<%
rs.MoveNext
wend
%>
<tr>
<td colspan="2"> <input type="hidden" name="num" value="<%=n%>">
<input id=submit type=submit value=Delete name=submit> </td>
</tr>
</table>
</form>
<p>
<%
else
Response.Write "No record found"
end if
rs.Close
cn.Close %>


This was the normal style used by me for common searching and listing type functions. And i have to copy and paste that code for all forms and listing options.

Plus in ASP 3.0 there was no option to properly reuse code normally reuse was for just basic component like header, footer and menu bar, but reusing source code and dynamic contents is difficult.

Code Using ASP.NET


Me.OleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.oledb.4.0; Data Source=C:\Inetpub\wwwroot\biblio\db\biblio.mdb"
Me.OleDbConnection1.Open()
Me.OleDbDataAdapter1.SelectCommand.CommandText = "Select ISBN,Title from Titles where title like'%" & TextBox1.Text & "%'"
Me.OleDbDataAdapter1.SelectCommand.Connection = Me.OleDbConnection1
Me.OleDbDataAdapter1.Fill(Me.DataSet1)
Me.DataGrid1.DataSource = Me.DataSet1
Me.DataGrid1.DataBind(
)Label1.Text = "Total " & Me.DataSet1.Tables(0).Rows.Count & " record(s) found"


This is total code that i had to write for this complete searching application. And Visual Studio simplifies process of adding user controls and changing its properties.

Its just like Visual Basic 6 like experience for building web applications.

Features


This small application have following features

1) Database connectivity to MS Access Database using ADO.NET
2) Webform controls
3) use of RequiredFieldValidator control
4) Query execution for MS Access database using Command object
5) Search record listing option using DataGrid control with paging option

About ASP.NET


ASP.NET is a great tool for building web application it have great support for new standard programming platforms like XML, Web Services, HTTP.

But most exciting feature are user controls that are pre-made objects and very easy to reuse in same old fashioned Visual Basic style.

Plus developers have option to create their own user controls or customize and subclass standard controls and making repeative alot easiy and less time consuming.

Click here to Download the Projec

 

Go to CodeProject.com
Go to hotscripts.com Go to 123aspx.com

 

 
 
Sponsored Links
 
   
 
  Currently <%=application("onlinevisitors")%> visitors online
 
My website is hosted by Munir Brothers Inc. host@munirbrothers.com