ASP.NET学习笔记(1)

来源:互联网 发布:xlsx软件下载 编辑:程序博客网 时间:2024/05/17 22:07

 两个listbox,实现双击其中一个listbox中的选项,自动添加到另一个:

 

<script language="javascript">
 function lstDeptFrom_DbClick()
 {
" " var addOption=document.createElement("option");
"  " var index1;
"  " if(document.form1.lstDeptFrom.length==0) return(false);
"  " index1=document.form1.lstDeptFrom.selectedIndex;
"  " if(index1<0) return(false);
"  " addOption.text=document.form1.lstDeptFrom.options(index1).text;
"  " addOption.value=document.form1.lstDeptFrom.value;
"  " document.form1.lstDeptTo.add(addOption);
"  " document.form1.lstDeptFrom.remove(index1);
 }

 function lstDeptTo_DbClick()
 {
" " var addOption2=document.createElement("option1");
"  " var index2;
"  " if(document.form1.lstDeptTo.length==0) return(false);
"  " index2=document.form1.lstDeptTo.selectedIndex;
"  " if(index1<0) return(false);
"  " addOption2.text=document.form1.lstDeptTo.options1(index2).text;
"  " addOption2.value=document.form1.lstDeptTo.value;
"  " document.form1.lstDeptFrom.add(addOption2);
"  " document.form1.lstDeptTo.remove(index2);
 }
</script> 

        lstDeptFrom.Attributes.Add("ondblclick", "lstDeptFrom_DbClick()");
        lstDeptTo.Attributes.Add("ondblclick", "lstDeptTo_DbClick()");

 

根据数据库中对应字段的值,来初始化checkbox的状态

 

        #region 初始化时对“有效”列checkbox的控制
        /// <summary>
        /// 根据数据库中disable的值,来初始化checkbox的状态
        /// </summary>
        private void resultDataTable_ItemCreated(object sender, DataGridItemEventArgs e)
        {
            CheckBox chk = null;
            // 对数据库中disable字段进行判断来确定checkbox的状态
            foreach (DataGridItem Item in resultDataTable.Items)
            {
                chk = (CheckBox)Item.FindControl("chkExport");
                if ("0".Equals(Item.Cells[1].Text.ToString()))
                {
                    chk.Checked = true;
                }
            }
            // 为页面上的每个checkbox都添加一个点击事件,来触发与数据库的交互
            if (chk != null)
            {
                chk.CheckedChanged += new EventHandler(chk_CheckedChanged);
            }
        }
        #endregion

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/moqingcn/archive/2009/06/12/4263292.aspx

原创粉丝点击