ASP.NET - repeater eval - Asked By sislines ag on 14-Feb-12 01:57 AM

The below code
in repeater inside item template -->

<asp:LinkButton ID="LinkButton3" Text='<%#Eval("Field1").ToString().Replace('"+ TextBox4.Text +"',"<font color=red>"+ TextBox4.Text +"</font>")%>' CommandName="itemz"  runat="server">LinkButton</asp:LinkButton>

I want to replace  the color in "field1 value" with  specific value found in textbox4 how to solve it

shows me unexpected error. how to solve it

e.g-->  "LiverPool"
Web Star replied to sislines ag on 14-Feb-12 02:15 AM
If you want to manipulate the text bind in repeater control at the time of bound datasource than you call function and pass the eval item to that function and do your desired task within that function and return value which is bind with that item in repeater as follows

<asp:LinkButton ID="LinkButton3" Text='<%# CallReplace( Eval("Field1").ToString() ) %>' CommandName="itemz"  runat="server">LinkButton</asp:LinkButton> 

and in that function code behind you can use your other code as follows

public string CallReplace ( string fieldVal)
string strFinal = "";
string strRep = TextBox4.Text.ToString();  
strFinal  fieldVal.Replace(strRep  ,"<font color=red>"+ strRep   +"</font>" );
return strFinal;
sislines ag replied to Web Star on 14-Feb-12 02:54 AM
thanks, it got worked
Web Star replied to sislines ag on 14-Feb-12 03:39 AM
You Welcome!
sislines ag replied to Web Star on 19-Feb-12 03:00 AM
hi ,
  I got 1 problem here , in order to convert in to color it choose only what i type in the textbox,  means if i type with small letter it only display color that matches to text-boxes. cannot take both, both capital and small letters. How i force or any tricks to solve it.
Web Star replied to sislines ag on 20-Feb-12 03:51 AM
than you need to replace with both small case and another with upper case , otherwise best is you can just convert in one case before replacing in you make sure that data having only one case. So i think best is you can replace with both case