zeidhaddadin Posted December 29, 2006 Share Posted December 29, 2006 Hi all,I'm trying to replace a word in the container.data when showing my database records like this: <%#Replace(Container.DataItem("Description"), search, <b>search</b>%> but it is giving me that search is not declared.. But I declared it before in the Sub page_load()Can someone tell me how to fix this,zeid Link to comment Share on other sites More sharing options...
zeroxp Posted January 2, 2007 Share Posted January 2, 2007 the Replace method is declared as:String.Replace Method (String, String) so try something similar to <%# Container.DataItem("Description").ToString().Replace("string1", "string2") %> Link to comment Share on other sites More sharing options...
zeidhaddadin Posted January 2, 2007 Author Share Posted January 2, 2007 Hi thank you for answering..I tried <%#Container.DataItem("Description").ToString.Replace("search", "<b>search</b>")%>But it only makes any keyword "search" be bold.. But I want it dynamical .. I mean I want it to be Replace(search, "<b>search</b>")so it changes any keyword the user search for..I tried it like this and still gave me search is not defined.Thank you!,zeid Link to comment Share on other sites More sharing options...
aspnetguy Posted January 2, 2007 Share Posted January 2, 2007 can you post your code. We'll need to see the page that submits the search word and the code for the page thjat displays the search results. Link to comment Share on other sites More sharing options...
zeidhaddadin Posted January 2, 2007 Author Share Posted January 2, 2007 Yeah sure..This is my normal form (index.aspx): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>zeid1</title><meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link type="text/css" rel="stylesheet" href="STYLE.css" /></head><body><form method="get" action="SEARCH.aspx"><table cellpadding="0" cellspacing="0" border="0"><tr><td><img src="images/zeid1.gif" alt="zeid1" /></td></tr><tr><td class="td1"> </td></tr><tr><td class="td1"><input type="text" name="search" size="32" /> <input type="submit" value="Search Db" /></td></tr><tr><td class="td1"> </td></tr></table></form><p class="p1">Developed and programmed using <span class="span1">ASP.NET</span> language</p><p class="p2">© 2007, <a href="INDEX.aspx">HOME PAGE</a> - <a href="SUBMIT.aspx">SUBMIT PAGE</a></p></body></html> And this is my Results page (search.aspx): <html><head><title>zeid1</title><meta http-equiv="content-type" content="text/html; charset=UTF-8" /><style type="text/css"><!--p { font-family : Verdana; font-size : 12px; } .p1 { font-size : 11px; text-align : center; } .p2 { font-size : 11px; text-align : justify; } .td1 { background-color : #F6F6F6; } .span1 { font-size : 11px; color : green; } a:link, a:active, a:visited, a:hover { color : #0000FF; }--></style></head><body><br /><center><table cellpadding="0" cellspacing="0" border="0"><tr><td width="750" height="25" class="td1"><p class="p2"> THE SEARCH PROCESS RETURNED WITH THE FOLLOWING RESULTS:</p></td></tr><tr><td width="750" height="25"> </td></tr><configuration><system.web><compilation debug="true" /></system.web></configuration><%@ Import Namespace="System.Data.OleDb" %><%@ Page Language="VB" Debug="true" %><script runat="server">Sub Page_Load()Dim search As StringDim strsearchDim count As IntegerDim sql As Stringsearch = Request.QueryString("search")strsearch = Split(search, " ")CheckLength(search)For count = 0 To UBound(strsearch)sql = "SELECT Url, Description, Date FROM Table1 WHERE Description LIKE '%" & strsearch(0) & "%' AND Description LIKE '%" & strsearch(count) & "%' OR Url LIKE '%" & search & "%' ORDER BY Date DESC"NextDim dbconn As OleDbConnectionDim dbcomm As OleDbCommandDim dbreaddbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("db/Database1.mdb"))dbcomm = New OleDbCommand(sql, dbconn)dbconn.Open()dbread = dbcomm.ExecuteReader()CheckHasRows(dbread)dbconn.Close()End subSub CheckHasRows(ByVal dbread)If dbread.hasrows ThenTable1.DataSource = dbreadTable1.DataBind()dbread.Close()ElseResponse.Redirect("/INDEX.aspx")End ifEnd subSub CheckLength(ByVal search As String)If Len(search) < 2 ThenResponse.Redirect("/INDEX.aspx")End ifEnd sub</script><form runat="server"><asp:Repeater id="Table1" runat="server"><ItemTemplate><tr><td width="750" height="17"><p><a href="<%#Container.DataItem("Url")%>"><%#Container.DataItem("Url")%></a></p></td></tr><tr><td width="750" height="17"><p><%#Container.DataItem("Description")%></p></td></tr><tr><td width="750" height="17"><p><span class="span1">INDEXED ON <%#Container.DataItem("Date")%></span></p></td></tr><tr><td width="750" height="10"> </td></tr></ItemTemplate></asp:Repeater></form><tr><td width="750" height="25" class="td1"> </td></tr></table></center><p class="p1">© 2007, <a href="INDEX.aspx">HOME PAGE</a></p></body></html> Thank you very much,zeid Link to comment Share on other sites More sharing options...
aspnetguy Posted January 2, 2007 Share Posted January 2, 2007 you should be able to do this <%#Container.DataItem("Description").ToString().Replace(search, "<b>" & search & "</b>")%> Link to comment Share on other sites More sharing options...
zeidhaddadin Posted January 2, 2007 Author Share Posted January 2, 2007 Man same error:Compiler Error Message: BC30451: Name 'search' is not declared Link to comment Share on other sites More sharing options...
pulpfiction Posted January 2, 2007 Share Posted January 2, 2007 guess reason for error is you have declared the variable "search" in page_load(), limited scope of variable... try declaring "search" as global.. Link to comment Share on other sites More sharing options...
zeidhaddadin Posted January 2, 2007 Author Share Posted January 2, 2007 yeah thank you did it like this:Public search As StringThanks,zeid Link to comment Share on other sites More sharing options...
pulpfiction Posted January 2, 2007 Share Posted January 2, 2007 Public search As StringYes thats global.. did that fix the error?? Link to comment Share on other sites More sharing options...
zeidhaddadin Posted January 3, 2007 Author Share Posted January 3, 2007 yeah! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now