469,647 Members | 1,728 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

Repeater Control with search capability

BlogListingAll.aspx
-------------------

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="user_BlogListingAll.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<center>

<form id="form1" runat="server">
<table border="0" width="786">
<tr>
<td width="349" align="left">

<table border="0">
<tr>
<td style="width: 299px">
<asp:Label ID="Label1" runat="server" Text="Label" Width="271px"
ForeColor="Red"></asp:Label></td>
</tr>
<tr>
<td style="width: 299px">
<asp:LinkButton ID="LinkButton1" runat="server"
OnClick="LinkButton1_Click1">Log Out</asp:LinkButton></td>
</tr>
</table>

</td>
<td width="427" align="right">

<table border="1" width="239" bordercolor="#FF0000">
<tr>
<td width="235">
<table border="0" width="232">
<tr>
<td width="93" style="text-align: left">
<asp:Label ID="Label5" runat="server" Font-Size="Small"
ForeColor="Black" Text="subscription" Width="49px">
</asp:Label></td>
<td width="123" style="text-align: left">
<asp:Label ID="Label6" runat="server" Font-Size="Small"
ForeColor="Black" Width="46px">
</asp:Label></td>
</tr>
<tr>
<td width="93" style="text-align: left">
<asp:HyperLink ID="HyperLink1" runat="server" Font-Size="Small"
NavigateUrl="user_SubscriptionCart.aspx">checkout</asp:HyperLink></td>
<td width="123"></td>
</tr>
</table>
</td>
</tr>
</table>

</td>
</tr>
</table>

<br />

<table border="0" width="786">
<tr>
<td width="100%" style="text-align: left" bgcolor="#666699">
<img src="photos/logo.gif" id="IMG1" />
</td>
</tr>
<tr>
<td>
<table border="0" width="775">
<tr>
<td width="46" style="text-align: left"><a
href="user_Main.aspx">Main</a></td>
<td width="87" style="text-align: left"><a
href="user_BlogDetail.aspx">Create Blog</a></td>
<td width="105" style="text-align: left"><a
href="user_CategoryListingAll.aspx">List Categories</a></td>
<td width="88" style="text-align: left"><a
href="user_SubscriptionListing.aspx">Subscription</a></td>
<td width="454" style="text-align: left"><a
href="user_EmailListingAll.aspx">Email</a></td>
</tr>
</table>
</td>
</tr>
</table>
<br /><br />
<table width="786">
<tr>
<td style="text-align: left">
<asp:Label ID="Label2" runat="server" ForeColor="Red"
Width="328px"></asp:Label></td>
</tr>
<tr>
<td style="text-align: left">
<asp:TextBox ID="TextBox1" runat="server">Search</asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="OK"
OnClick="Button1_Click" />
</td>
</tr>
</table>
<br /><br />
<table border="0" width="786">
<asp:Repeater ID="rptItems" runat="server">
<ItemTemplate>
<tr>
<td width="156" valign="top"><%# "<img src='" + Eval("ThumbPath") +
"'>" %></td>
<td width="627" valign="top" align="left">
<%# "<a href=user_BlogListing.aspx?VideoID=" + Eval("VideoID") + ">"
+ Eval("Name") + "</a>" + " " + "Created " + Eval("DateTime") %>
<br /><br />
<%# getNewString(Eval("VideoDescription").ToString()) %>
</td>
</tr>
<tr>
<td colspan="2"><span style="color:
silver">----------------------------------------------------------------
-----------------------------------------------------------------</span>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<br />
<asp:Repeater ID="rptPages" Runat="server">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><b>Page:</b>&nbsp;</td>
<td>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage"
CommandName="Page"
CommandArgument="<%#
Container.DataItem %>"
CssClass="text"
Runat="server"><%# Container.DataItem %>
</asp:LinkButton>&nbsp;
</ItemTemplate>
<FooterTemplate>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
<br /><br />

<table border="0" width="786">
<tr>
<td width="100%" bgcolor="#666699">&nbsp;</td>
</tr>
<tr>
<td width="100%" style="font-family: Arial; font-size: 12px;"></td>
</tr>
</table>
</center>
</body>
</html>
BlogListingAll.aspx.cs
----------------------

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using MyProject;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["login"].ToString() != "1")
{
Response.Redirect("user_Login.aspx");
}
else
{
Label1.Text = "welcome " + Session["email"];
}

int numSubscription;
numSubscription = ((ArrayList)this.Session["Address"]).Count;
Label6.Text = numSubscription.ToString();

if (numSubscription == 0)
{
HyperLink1.Enabled = false;
}

if (!Page.IsPostBack)
LoadData("");
}

public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
rptPages.ItemCommand +=
new RepeaterCommandEventHandler(rptPages_ItemCommand);
}

private void LoadData(String sqlQuery)
{
String CategoryID = Request.QueryString["CategoryID"];

if (sqlQuery.Length == 0)
{
sqlQuery = "SELECT VideoID, Name, VideoDescription,
ThumbPath, DateTime FROM Video WHERE CategoryID=" + CategoryID;
}

SqlConnection cn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["myConnection"].Con
nectionString);
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlQuery, cn);
DataTable dt = new DataTable();
da.Fill(dt);
cn.Close();

PagedDataSource pgitems = new PagedDataSource();
DataView dv = new DataView(dt);
pgitems.DataSource = dv;
pgitems.AllowPaging = true;
pgitems.PageSize = 2;
pgitems.CurrentPageIndex = PageNumber;

if (pgitems.PageCount 1)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1)).ToString();
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
{
rptPages.Visible = true;
}

rptItems.DataSource = pgitems;
rptItems.DataBind();
}

public String getNewString(String newstring)
{
if(newstring.Length 20)
{
return newstring.Substring(0, 20);
}
else
{
return newstring;
}
}

protected void rptPages_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
LoadData("");
}
protected void LinkButton1_Click1(object sender, EventArgs e)
{
Session["login"] = 0;
Response.Redirect("user_Login.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
String CategoryID = Request.QueryString["CategoryID"];
LoadData("SELECT VideoID, Name, VideoDescription, ThumbPath,
DateTime FROM Video WHERE VideoDescription Like" + "'%" + TextBox1.Text
+ "%' AND CategoryID=" + CategoryID);
}
}
The problem with the code above is that the search functionality works
well, however it is not reflected on the navigation links (e.g
1,2,3...). That means after searching for a record, when I click on the
navigation links the normal results are displayed instead of the search
result. How do I solve the problem?

Your help is kindly appreciated.

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Apr 14 '07 #1
0 1053

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by huzz | last post: by
1 post views Thread by Maziar Aflatoun | last post: by
1 post views Thread by ratnakarp | last post: by
4 posts views Thread by John Kotuby | last post: by
1 post views Thread by jazzart | last post: by
15 posts views Thread by | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.