0

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?

2
  • Try changing your db column to nvarchar, because "0" is not the same as 0. Commented Nov 15, 2012 at 9:06
  • Not, sure about your code snippet. msdn.microsoft.com/en-us/library/4hx47hfe(v=vs.100).aspx Here another params: container item + field Or you just write fast example? Commented Nov 15, 2012 at 9:11

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the solution - I implemented this and the values are picking up as needed :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.