2

中继器中有 4 个 readiobutton,我试图从数据库值中显示选中的单选按钮。

<asp:RadioButton ID="rb_option1" GroupName="answer" CssClass="frm_label"
    Checked='<%# IIF(Eval("ANSWER")==1,true,false) %>'
     Text='<%# Eval("OPTION1")%>' runat="server" />

第二种方法

<asp:RadioButton ID="rb_option1" GroupName="answer" CssClass="frm_label"
Checked='<%# Eval("ANSWER")==1 ? true : false %>'
 Text='<%# Eval("OPTION1")%>' runat="server" />

其余的单选按钮依此类推。但是,它显示错误Expression Expected错误。需要帮忙。!!

4

1 回答 1

1

It looks like you've got your C# and VB.Net mixed. Your first example looks like VB, the second like C#. However, you've got a few problems in your VB implementation:

  • The equality operator in VB is =, not ==
  • You should use the IF operator, not the IIF function, which is obsolete

The correct code should be as follows:

<asp:RadioButton ID="rb_option1" GroupName="answer" CssClass="frm_label"
  Checked='<%# IF(Eval("ANSWER")=1,true,false) %>'
  Text='<%# Eval("OPTION1")%>' runat="server" />
于 2012-08-02T12:09:02.847 回答