Solved

Search feature not working - ASP.net (aspx) 4.0

Posted on 2010-11-10
5
325 Views
Last Modified: 2012-08-13
Admittedly I do not know what else to do at this point. I have spent the last week trying to figure out how to do paging with a datalist contol. I have to use a datalist because I need the formatting freedom. I thought I could get the pages to work but Something is missing.

1. The pages load ok.
2. I don't receive any compile errors.
3. The next, previous, last buttons are clickable

The BIG PROBLEM IS my search page does not bring back any results. If it is bringing back results they are not displaying on the page. My assumption is no results are being returned. I think it would be too much code to try and place here so I am attaching the aspx file in text format and the aspx.vb file also in text format. I can't tell you where I'm going wrong with this so someone will have to look through the code to determine the problem. I've tried everything I know to do at this point. I thought about searching for some more sample code of datalist paging but I figured since the pages are not failing then maybe I am very close to making this work. PLEASE HELP!!!!!!!!!!!!!!!!! search.txt
search-aspx-vb-CodeBehind.txt
0
Comment
Question by:derrekdeveloper
  • 4
5 Comments
 

Author Comment

by:derrekdeveloper
ID: 34107213
I wanted to add that I do get search results in the non-paging version og the pages where I'm just using an SQLdatasource binding to the datalist.
0
 
LVL 17

Accepted Solution

by:
ToAoM earned 500 total points
ID: 34111050
Because you're doing a response.Redirect, a new request will be made, and I can't see where you're passign or storing the string to search, so my guess is that your actual query is getting lost in the redirect.

Instead of passing the page number in the query string, store it in the viewstate of the page. and just Databind after upping the current page number.
0
 

Assisted Solution

by:derrekdeveloper
derrekdeveloper earned 0 total points
ID: 34111978
I tossed that code based. I couldn't really understand what the author ws doing. When I tested his page on a site it didn't work either. However, this code does work that I found.

<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="System.Data.SqlClient" %>
<html>
<head>
<title>Paging in Datalist - by Das</title>

<script language="vb" runat="server">

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack() Then
intPageSize.Text = "5"
intCurrIndex.Text = "0"
DataBind()
End If
End Sub

Private Sub DataBind()
Dim objConn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim objDA As New SqlDataAdapter("exec sp_das_sales_sel", objConn)
Dim objDS As New DataSet()

If Not Page.IsPostBack() Then
objDA.Fill(objDS)
intRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
objDS = Nothing
objDS = New DataSet()
End If

objDA.Fill (objDS, Cint(intCurrIndex.Text), CInt(intPageSize.Text), "Sales")

dList.DataSource = objDS.Tables(0).DefaultView
dList.DataBind()
objConn.Close()
PrintStatus()
End Sub

Public Sub ShowFirst(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = "0"
DataBind()
End Sub


Public Sub ShowPrevious(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = Cstr(Cint(intCurrIndex.Text) - CInt(intPageSize.Text))
If CInt(intCurrIndex.Text) < 0 Then
intCurrIndex.Text = "0"
End If
DataBind()
End Sub

Public Sub ShowNext(ByVal s As Object, ByVal e As EventArgs)
If CInt(intCurrIndex.Text) + 1 < CInt(intRecordCount.Text) Then
intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) + CInt(intPageSize.Text))
End If
DataBind()
End Sub

Public Sub ShowLast(ByVal s As Object, ByVal e As EventArgs)
Dim tmpInt as Integer

tmpInt = CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)
If tmpInt > 0 Then
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - tmpInt)
Else
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - CInt(intPageSize.Text))
End If
DataBind()
End Sub

Private Sub PrintStatus()
lblStatus.Text = "Total Records:<b>" & intRecordCount.Text
lblStatus.Text += "</b> - Showing Page:<b> "
lblStatus.Text += CStr(CInt(CInt(intCurrIndex.Text) / CInt(intPageSize.Text)+1))
lblStatus.Text += "</b> of <b>"

If (CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)) > 0 Then
lblStatus.Text += CStr(CInt(CInt(intRecordCount.Text) / CInt(intPageSize.Text)+1))
Else
lblStatus.Text += CStr(CInt(intRecordCount.Text) / CInt(intPageSize.Text))
End If
lblStatus.Text += "</b>"
End Sub

</script>
</head>
<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">
<h2 align="center"><font face="verdana">Paging in DataList</font></h2>
<a name="this"></a>

<asp:DataList ID="dList" Runat="server" Width="100%"
ItemStyle-BackColor="Beige"
ItemStyle-Font-Name="Verdana"
BorderWidth="1"
HeaderStyle-Font-Name="Verdana"
EnableViewState="False">

<HeaderTemplate>
<table width="100%" style="font: 10pt verdana" cellpadding=0 cellspacing=0>
<tr style="background-color:FF0000">
<th align=left><font color="#FFFFFF">Store ID</font></th>
<th align=left><font color="#FFFFFF">Order Number</font></th>
<th align=left><font color="#FFFFFF">Order Date</font></th>
<th align=left><font color="#FFFFFF">Qty</font></th>
<th align=left><font color="#FFFFFF">Description</font></th>
<th align=left><font color="#FFFFFF">Title ID</font></th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr style="background-color:#f5f5dc">
<td><%# DataBinder.Eval(Container.DataItem, "stor_id") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "ord_num") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "ord_date") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "qty") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "payterms") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "title_id") %></td>
</tr>
</ItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:DataList>

<table width=100% align="right">
<tr>
<td width=76% align=left>
<asp:label ID="lblStatus"
Runat="server"
Font-Name="verdana"
Font-Size="10pt" />
</td>

<td width=6%>
<a href="datalistpaging.aspx#this"
ID="hrefFirst"
onserverclick="ShowFirst"
runat="server"><b><<</b></a>
</td>

<td width=6%>
<a href="datalistpaging.aspx#this"
ID="hrefPrevious"
onserverclick="ShowPrevious"
runat="server"><b><</b></a>
</td>

<td width=6%>
<a href="datalistpaging.aspx#this"
ID="hrefNext"
onserverclick="ShowNext"
runat="server"><b>></b></a>
</td>

<td width=6%>
<a href="datalistpaging.aspx#this"
ID="hrefLast"
onserverclick="ShowLast"
runat="server"><b>>></b></a>
</td>
</tr>
</table>

<asp:label ID="intCurrIndex"
Visible="False"
Runat="server" />
<asp:label ID="intPageSize"
Visible="False"
Runat="server" />

<asp:label ID="intRecordCount"
Visible="False"
Runat="server" />

</form>
</body>
</html>
0
 

Author Comment

by:derrekdeveloper
ID: 34112006
I do believe that ToA0M's solution would hae worked. However, I found some datalist paging code that works and is easy to implement.
0
 

Author Closing Comment

by:derrekdeveloper
ID: 34143341
Both solutions work.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now