[英]ASP.NET C# Eval not reading values out of db
請幫助 - 我有一個listview查找db中的整數值,然后將其傳遞給codebehind以檢查db值是否為0 - 在這種情況下,它將顯示相應的消息。
它看起來像這樣:在aspx頁面上:
<ItemTemplate>
<ul>
<%# List(Eval("p1", "Personal Info Verification")) %>
<%# List(Eval("p2", "Medical History Part One")) %>
<%# List(Eval("p3", "Medical History Part Two")) %>
</ul>
</ItemTemplate>
並在cs頁面上:
public string List(string input)
{
if (input == "0")
return "<li>" + input + "</li>";
return "<li>value not 0</li>";
}
但它不起作用 - 即使db記錄肯定包含幾個0,也會返回'value not 0'。 不確定它是否與db值是一個整數而不是nvarchar有關? 我可能會遺失任何建議或其他內容?
您也可以在數據綁定的代碼隱藏中使用Eval
(在%#
上始終為true)。 我會嘗試解析它:
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.