CheckBox中的内联代码 [英] Inline code in CheckBox

查看:100
本文介绍了CheckBox中的内联代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想设置带有内联代码的复选框选中的属性,如果可能的话,请帮帮我.
我的代码是:-

Hi all,

I want to set checkboxes checked property with inline code if possible please help me.
my code is : -

<itemtemplate>
         <a href="#" önclick="newWin('<%#Eval(" userid=") %>');">View</a>
         <asp:CheckBox ID="chk1" runat="server" Checked='<% if(Eval("IsApproved") == (object) 1){%> true <%;} else { %>false <%;} %>' AutoPostBack="true" />
     </itemtemplate>



我收到错误消息:-



I am getting error: -

Cannot create an object of type ''System.Boolean'' from its string representation ''<% if(Eval("IsApproved") == (object) 1){%> true <%;} else { %>false <%;} %>'' for the ''Checked'' property.

推荐答案

以这种方式尝试.

Try it in this way .

<itemtemplate>
         <a href="#" önclick="newWin(''<%#Eval(" userid=") %>'');">View</a>
         <asp:checkbox id="chk1" runat="server" checked="<%# (Convert.ToBoolean(Eval("IsApproved")) ? true : false ) %>" autopostback="true" xmlns:asp="#unknown" />
     </itemtemplate>
<asp:templatefield xmlns:asp="#unknown"></asp:templatefield>


这样就可以了.
我已经在此处


This will do the job.
I had provided similar kind of answer of here


这篇关于CheckBox中的内联代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆