• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

Urgent - How to use Alphabetical anchor tags to search in the database in an asp.net application with vb.net coding?

I have a search form which will have alphabetical listing in the main form.

When the user clicks on a specific alphabet it should search in the database for that particular alphabet and brings the results as a datagrid of the lastnames which will starts with that alphabet and should display as a separate page.

How can I accomplish this task?

Mine is a ASP.net application and I am using VB.net for my coding.  Please help
0
amruthanet
Asked:
amruthanet
1 Solution
 
fizchCommented:
Your alphabetic link should open a new window passing the indicated letter in either the query string or hiding it in the form and use a parent / child relationship (probably not the right terminology) to access the variable. In this window will be a page that you create that queries the database and binds the results to the dataset.


Your links should look something like this:
 <a href="myResultspage.aspx?LetterId=a" target=_blank>A</a>
 <a href="myResultspage.aspx?LetterId=b" target=_blank>B</a>
 <a href="myResultspage.aspx?LetterId=c" target=_blank>C</a>
 <a href="myResultspage.aspx?LetterId=d" target=_blank>D</a>
etc...

MyResults should do something like this:

  Dim lastInitial as string
  try
     lastInitial = Request.QueryString("LetterId")
     dim sSql as string = "SELECT LastName FROM myTable WHERE LastName LIKE '" & lastInitial & "%'"

     dim myConnection as new SqlConnection (connectionString)
     dim myCommand as new SqlCommand(sSql, myConnection)

     myConnection.Open
     
     dim myReader as SqlDataReader = myCommand.ExecuteReader()

    myDataGrid.DataSource = myReader
    myDataGrid.DataBind()
  catch
    ' this try catch block will catch problems with the database connections
    ' you should put in logic to make sure the data in the query string is what you are expecting
  end try
0
 
amruthanetAuthor Commented:
Thanks.  It is working fine.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now