需求:一個用戶表 字段為 名字,年齡 和性別 (性別是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 + "')";
}
}
}
ListView控件,加一個客戶端的JS代碼,就不能插入、更新了!?
郎朗坤
2018-12-07 09:50:45