ironhide1975
Programmer
We're looking at some custom code for a page that displays search results. The code looks like it was created under an ASP.NET 1.1 structure. The following code creates the Previous/Next buttons and counts the results. Can someone help me create a Function to add the Page numbers in between these Previous/Next button.
Code:
protected void ShowResults(SearchResultItemCollection items, int nTotal, long nTimeUsed)
{
int nCount = 0;
if(items != null)
{
nCount = items.Count;
}
Total = nTotal;
//m_lblTotal.Text = string.Format("Found: {0} documents", nTotal);
m_lblTotal.Text = string.Format("Results <strong>{0}</strong> to <strong>{1}</strong> of <strong>{2}</strong>", Offset + 1, Offset + nCount, Total);
ShowButtons();
if(nCount > 0)
{
m_dgResults.DataSource = items;
m_dgResults.DataBind();
}
if(nTotal <= 0)
{
m_divSearchWithinResults.Visible = false;
m_tblDrillDown.Visible = false;
m_dgResults.Visible = false;
m_lblNoResults.Visible = true;
m_lblTotal.Visible = false;
}
else
{
m_divSearchWithinResults.Visible = true;
m_tblDrillDown.Visible = true;
m_dgResults.Visible = true;
m_lblNoResults.Visible = false;
m_lblTotal.Visible = true;
}
}
protected void ShowButtons()
{
if(Total > Hits)
{
m_btnNext.Visible = true;
m_btnNext2.Visible = true;
}
if((Offset + Hits) >= Total)
{
m_btnNext.Visible = false;
m_btnNext2.Visible = false;
}
else
{
m_btnNext.Visible = true;
m_btnNext2.Visible = true;
int n = Total - (Offset + Hits);
if(n < Hits)
{
m_btnNext.Text = string.Format("next {0} >>", n);
m_btnNext2.Text = string.Format("next {0} >>", n);
}
else
{
m_btnNext.Text = string.Format("next {0} >>", Hits);
m_btnNext2.Text = string.Format("next {0} >>", Hits);
}
}
if(Offset > 0)
{
m_btnPrev.Visible = true;
m_btnPrev2.Visible = true;
if(Offset > Hits)
{
m_btnPrev.Text = string.Format("<< previous {0}", Hits);
m_btnPrev2.Text = string.Format("<< previous {0}", Hits);
}
else
{
m_btnPrev.Text = string.Format("<< previous {0}", Offset);
m_btnPrev2.Text = string.Format("<< previous {0}", Offset);
}
}
else
{
m_btnPrev.Visible = false;
m_btnPrev2.Visible = false;
}
}