Help please - I have a listview looking up integer values from a db, then passes it to the codebehind to check if the db value is 0 - in which case it will display the appropriate message.
It looks something like this: On the aspx page:
<ItemTemplate>
<ul>
<%# List(Eval("p1", "Personal Info Verification")) %>
<%# List(Eval("p2", "Medical History Part One")) %>
<%# List(Eval("p3", "Medical History Part Two")) %>
</ul>
</ItemTemplate>
and on the cs page:
public string List(string input)
{
if (input == "0")
return "<li>" + input + "</li>";
return "<li>value not 0</li>";
}
But it doesn't work - the 'value not 0' is returned even though the db record definitely contains a couple of 0's. Not sure if it has something to do with the db value being an integer and not nvarchar? Any suggestions or something else I could be missing?
You can use Eval
also in codebehind on databinding(always true on %#
). I would try to parse it:
private string List(string key)
{
int input = int.Parse(Eval(key).ToString()); // note that the second argument is the format
return "<li>" + input + "</li>";
return "<li>value not 0</li>";
}
aspx
<ItemTemplate>
<ul>
<%# List("p1") %>
<%# List("p2") %>
<%# List("p3") %>
</ul>
</ItemTemplate>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.