首页 新闻 会员 周边

ListView控件,加一个客户端的JS代码,就不能插入、更新了!?

0
悬赏园豆:10 [已解决问题] 解决于 2013-06-05 21:47

需求:一个用户表 字段为 名字,年龄 和性别 (性别是CheckBox ),要求:CheckBox 选中时为男性,不必填写年龄,(即插入项,年龄输入框隐藏,[color=#FF6600]用js实现[/color])不选中时为女,年龄框可见,

js和程序效果我都实现了,奇哉怪也的是:InputAttributes["onchange"] = "changeed(this,'" + txtage.ClientID + "')";时, 插入,更新都不可用了!!即在 编辑、插入时,填好数据后,点更新或插入,数据会被清空,且维持编辑状态不变,经探索:毛病出在 "changeed(this,'" + txtage.ClientID + "')"; 把此javascript函数的形式改一下 即 不用txtage.ClientID 或其他字符串时,该现象就会消失!!
不知所以然,望高手指教
我的源代码在:http://www.w8le.com/lkfup/Solution1.rar

 

        protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem || e.Item.ItemType == ListViewItemType.InsertItem)
            {
                CheckBox chb = e.Item.FindControl("UserGenderCheckBox") as CheckBox;
                TextBox txtage = e.Item.FindControl("UserAgeTextBox") as TextBox;
                if (chb != null && txtage !=null)
                {
                    //chb.Attributes["onchange"] = "changeed(this,'" + txtage.ClientID + "')"; 
                    chb.InputAttributes["onchange"] = "changeed(this,'" + txtage.ClientID + "')";
                }
            }
        }
钢的锅的主页 钢的锅 | 初学一级 | 园豆:10
提问于:2013-03-16 13:48
< >
分享
最佳答案
0

这种应该在页面中做,绑定的时候,在模板中做好

可以参考 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemtemplate.aspx

 

收获园豆:10
陈希章 | 老鸟四级 |园豆:2538 | 2013-03-16 15:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册