从C#后台输出JS代码

     // 这里是主表输出是 自定义表格格式函数
        private bool bSwitch = false;
        string color1 = "#ffffcc";
        string color2 = "#ccff99";

        /// <summary>
        /// 定义搜索后列表 主表样式输出
        /// </summary>
        /// <param name="con"></param>
        /// <returns></returns>
        public string TRJavaScript(Control con)
        {
            string tmp;
            DataListItem dli = con as DataListItem;
            Button btn = dli.FindControl("HiddenButton") as Button;
            string _js = "bgcolor={0} onMouseover='rowcolor=this" +
                         ".style.backgroundColor;this.style.backgroundColor" +
                         "=\"#00FF28\"; this.style.cursor = \"hand\"' " +
                         "onMouseout='this.style.backgroundColor=rowcolor;' " +
                         " onclick='document.getElementById(\"{1}\").click();' ";
            tmp = bSwitch ? string.Format(_js, color1, btn.ClientID) :
                           string.Format(_js, color2, btn.ClientID);
            bSwitch = !bSwitch;
            return tmp;
        }

 

posted on 2013-01-31 08:36  pagerd  阅读(482)  评论(0)    收藏  举报