需求:一個(gè)用戶(hù)表 字段為 名字,年齡 和性別 (性別是CheckBox ),要求:CheckBox 選中時(shí)為男性,不必填寫(xiě)年齡,(即插入項(xiàng),年齡輸入框隱藏,[color=#FF6600]用js實(shí)現(xiàn)[/color])不選中時(shí)為女,年齡框可見(jiàn),
js和程序效果我都實(shí)現(xiàn)了,奇哉怪也的是:InputAttributes["onchange"] = "changeed(this,'" + txtage.ClientID + "')";時(shí), 插入,更新都不可用了?。〖丛?編輯、插入時(shí),填好數(shù)據(jù)后,點(diǎn)更新或插入,數(shù)據(jù)會(huì)被清空,且維持編輯狀態(tài)不變,經(jīng)探索:毛病出在 "changeed(this,'" + txtage.ClientID + "')"; 把此javascript函數(shù)的形式改一下 即 不用txtage.ClientID 或其他字符串時(shí),該現(xiàn)象就會(huì)消失??!不知所以然,望高手指教我的源代碼在: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控件,加一個(gè)客戶(hù)端的JS代碼,就不能插入、更新了!?
郎朗坤
2018-12-07 09:50:45