Following code can be used to display images and titles of searched sale items by price. Viz. by entering any price and clicking search button will display the images and titles of those sale items which cost around specified price range viz. Specified range + or -2. For ex:If you type 35 then, all sale items whose cost is between 33 and 37 will be displayed.
All table rows are generated during run time and corresponding data is fetched from the database and displayed.
Imports System.Data Imports System.Data.OleDb Partial Class SearchResults Inherits System.Web.UI.Page Public y As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "" Dim sc As New OleDbConnection Dim scm1 As New OleDbCommand y = Request.QueryString("b") Dim a As String = y - 2 Dim b As String = y + 2 Dim dap1 As New OleDbDataAdapter Dim ds1 As New DataSet Dim i As Integer
sc.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("SiteSqlServer") scm1.CommandText = "select * from ITEM_MASTER where ITEM_PRICE BETWEEN " & CType(a, Integer) & " AND " & CType(b, Integer) & "" scm1.Connection = sc dap1.SelectCommand = scm1 dap1.Fill(ds1)
Dim tmpRowIdx As Integer = 0
For i = 0 To ds1.Tables(0).Rows.Count - 1 tmpRowIdx = i \ 3 If (tmpRowIdx + 1 > Table1.Rows.Count) Then Dim tmpRow As New TableRow Table1.Rows.Add(tmpRow) End If
addCellToTable(tmpRowIdx, ds1.Tables(0).Rows(i).Item("ITEM_IMAGE"), ds1.Tables(0).Rows(i).Item("ITEM_DESCRIPTION"), ds1.Tables(0).Rows(i).Item("ITEM_ID"))
Next
If ds1.Tables(0).Rows.Count = 0 Then Label1.Text = "" Label1.Text = "No results found"
End If End Sub Function FormatURL(ByVal strArgument) As String Return (strArgument) End Function Private Sub addCellToTable(ByVal pRowIdx As Integer, ByVal pImageUrl As String, ByVal pDescription As String, ByVal pItemId As String) Dim tmpCell As New TableCell Dim tmpImage As New ImageButton Dim tmpDesc As New Label
tmpImage.ImageUrl = pImageUrl tmpImage.Style.Add("Align", "Center") tmpImage.OnClientClick = "window.open('BuyButtonPage1.aspx?a=" & pItemId & "', 'myWindow')" 'A013"
tmpDesc.Text = pDescription tmpDesc.Width = "200" tmpDesc.Font.Bold = True tmpDesc.Font.Size = "12" tmpDesc.Font.Name = "Arial" tmpDesc.ForeColor = Drawing.Color.DarkGreen tmpDesc.Style.Add("Align", "Center")
tmpCell.Controls.Add(tmpImage) tmpCell.Controls.Add(tmpDesc) tmpCell.Width = "200" tmpCell.HorizontalAlign = HorizontalAlign.Center
Table1.Rows(pRowIdx).Cells.Add(tmpCell) End Sub
End Class
|
No responses found. Be the first to respond and make money from revenue sharing program.
|