Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkign Value

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
I have a repeater where I am showing the values via:

Code:
<%#DataBinder.Eval(Container.DataItem, "field")%>

I need to be able to check this value and if it is a certain value, then change some of the HTML - I tried:

Code:
string var = DataBinder.Eval(Container.DataItem, "field");

but I get an error... how could I do this?

[conehead]
 
DataBinder.Eval(Container.DataItem, "field") returns an Object, and you are comparing it to a string. Try casting it to a string, that should work:

(string)DataBinder.Eval(Container.DataItem, "field")
 
ok I tried:

Code:
string tun = (string)DataBinder.Eval(Container.DataItem, "field");

and

Code:
string tun = DataBinder.Eval(Container.DataItem, "field").ToString();

and I am still getting the same error on the word 'Container' :: The type or namespace 'Container' could not be found (are you missing a using directive or an assembly reference?)


[conehead]
 
Code:
<%#  CheckForSomething(Convert.ToString(DataBinder.Eval(Container.DataItem, "field")))%>

Code:
protected string CheckForSomething(string strField)
{
   // do your logic here
   // if(strField == "foo")
   //     return "bar";


}
 
You should really to the checking in the RowDataBound event. Simply bind the Repeater as you've done above and then use e.Row.Cells to get the relevant cell and text. Do you checking and change the value as is needed.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top