日期:2014-05-18  浏览次数:20432 次

简单问题,单选按钮组如何判断选中问题???
如题,我从数据库里提出0和1的值一判断,如果是1我就让男
<asp:RadioButtonList ID="R_operat" runat="server" RepeatDirection="Horizontal" Width="174px">
  <asp:ListItem Value="1" Selected='<%=DataBinder.Eval(Container,"DataItem.operating")==1?true:false %>'>男</asp:ListItem>
  <asp:ListItem Value="0" Selected='<%=DataBinder.Eval(Container,"DataItem.operating")==1?true:false %>'>女</asp:ListItem>
</asp:RadioButtonList>

上面这个控件是绑定在DataList的ItemTemplate模板里的,我像这样判断它老是默认女为选中(而不管数据库是的值是1和0)



------解决方案--------------------
因为 
<asp:ListItem Value="1" Selected= ' <%=DataBinder.Eval(Container,"DataItem.operating")==1?true:false % > '>男</asp:ListItem > 
<asp:ListItem Value="0" Selected= ' <%=DataBinder.Eval(Container,"DataItem.operating")==1?true:false % > '>女</asp:ListItem > 
中你都是判断当结果==1为true,这样的话,就是先选男再选女,你看到的是最后结果,将女的那个改为 <%=DataBinder.Eval(Container,"DataItem.operating")==0?true:false % > '>女。
------解决方案--------------------
<asp:Label ID="lblTitle" runat="server" Text='<%#Eval("operating").ToString()=="1"?"男":"女"'></asp:Label>
这样试试看!

------解决方案--------------------
1.
<asp:RadioButtonList ID="R_operat" runat="server" RepeatDirection="Horizontal" Width="174px" > 
<asp:ListItem Value="1" Selected= ' <%=DataBinder.Eval(Container,"DataItem.operating")==1?true:false % > ' >男 </asp:ListItem > 
<asp:ListItem Value="0" Selected= ' <%=DataBinder.Eval(Container,"DataItem.operating")==0?true:false % > ' >女 </asp:ListItem > 
</asp:RadioButtonList > 

2.在后台写
findControlByValue().selected = true;
------解决方案--------------------
你把<%= %> 换成 <%# %>