如何在内联 if 语句中使用数据绑定记录
这是我的问题:
我的 asp.net (VB) 上有一个中继器:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Question_Number") %>' />
<%#Eval("Question_Desc")%>
现在我想做的是,检查一个我没有使用过的值,称为“Question_Type”,它可能是 = 1、2 或 3取决于它是否是多项选择、简答题等。
我已经尝试过:
<%
if Eval("Question_type") = 1 then
Response.Write(" <asp:RadioButton runat=""server"">test1</asp:RadioButton>")
Response.Write(" <asp:RadioButton runat=""server"">test2</asp:RadioButton>")
Response.Write(" <asp:RadioButton runat=""server"">test3</asp:RadioButton>")
end if
%>
并且收到此错误:
数据绑定方法(例如 Eval()、XPath() 和 Bind() 只能在数据绑定控件的上下文中使用) 。
我如何在 if 语句中使用这个值???
here is my problem:
I've got a repeater on my asp.net (VB):
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Question_Number") %>' />
<%#Eval("Question_Desc")%>
Now what I want to do is, check a value that I haven't used called "Question_Type" which could be = 1, 2 or 3 depending if it is multiple choice, short answer, etc.
I have tried this:
<%
if Eval("Question_type") = 1 then
Response.Write(" <asp:RadioButton runat=""server"">test1</asp:RadioButton>")
Response.Write(" <asp:RadioButton runat=""server"">test2</asp:RadioButton>")
Response.Write(" <asp:RadioButton runat=""server"">test3</asp:RadioButton>")
end if
%>
and I get this error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
HOW can I use this value in a if statement???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要处理 ItemDataBound 事件并手动处理那里的值。
以下是我如何处理给定此中继器的问题:
这是我的事件处理程序,用于获取单选按钮列表的可能答案:
You are going to need to handle the ItemDataBound event and manually handle the values there.
Here is how I might approach the problem given this repeater:
Here is my event handler for getting the possible answers to a radio button list: