Get Container.DataItem in Repeater on If Statement
I'm trying to use an if statement in a repeater to decide whether or not to display a field.
Code:
<% If DataBinder.Eval(Container.DataItem, "memtype") = "P" Then %>
HTML TO SHOW A PICTURE
<% End If %>
I get an error saying Container isn't defined. I'm using a PagedDataSouce from a DataSet. Any ideas?
Thanks, Aaron
Re: Get Container.DataItem in Repeater on If Statement
I'm guessing you have this if statement within the repeater itemtemplate.
Best thing to do is call a method passing in arguments like so:
Code:
<%# displayImage( (string) DataBinder.Eval(Container.DataItem, "memtype") ) %>
and then in the code behind:
Code:
string displayImage(string MemType) {
if (MemType == "P") {
//return string of HTML to display image
}
}
Is that what you were after?
DJ
Re: Get Container.DataItem in Repeater on If Statement
is there a way to do this in vb.net?
I get the error "Overload resolution failed because no accessible 'ToString' can be called with these arguments"
VB Code:
<%# showDist(DataBinder.Eval(Container.DataItem, "distance"))%>
Re: Get Container.DataItem in Repeater on If Statement
Nevermind, I got it...thanks a lot