zoukankan      html  css  js  c++  java
  • Gridview绑定方法和选择方法的应用

        private void GridViewBind()
        {
            GridView1.DataSource = 数据源;
            GridView1.DataKeyNames = new string[] {"id" };//用数组来指定
            GridView1.DataBind();
        }


    gridview中的一些特效.
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //高亮显示指定行
                e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
                e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
                //进行时间格式化
                e.Row.Cells[5].Text = Convert.ToDateTime(e.Row.Cells[5].Text).ToShortDateString();
                //删除指定行数据时,弹出询问对话框
                ((LinkButton)(e.Row.Cells[8].Controls[0])).Attributes.Add("onclick", "return confirm('是否删除当前行数据!')");
                //多余字 使用...显示
                //StringFormat.Out是自定义的一个方法,等于substring()
                e.Row.Cells[1].Text = StringFormat.Out(e.Row.Cells[2].Text, 7);
                e.Row.Cells[2].Text = StringFormat.Out(e.Row.Cells[2].Text, 16);
            }
        }

    gridview中选择按钮的应用
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            string id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
            Response.Write("<script> window.open('DetailLeaguerInfo.aspx?id=" + id + "','','scrollbars') </script>");
            Response.Write("<script>history.go(-1)</script>");
        }


      if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //高亮显示指定行
                e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
                e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
                //设置审核状态,并且设置相应的颜色。
                if (e.Row.Cells[5].Text == "False")
                {
                    e.Row.Cells[5].Text =StringFormat.HighLight("未审核",true);
                }
                else
                {
                    e.Row.Cells[5].Text = StringFormat.HighLight("已审核", false);
                }
                //多余字 使用...显示
                e.Row.Cells[2].Text = StringFormat.Out(e.Row.Cells[2].Text, 18);

            }

  • 相关阅读:
    爬虫第二弹之http协议和https协议
    爬虫第一弹之py爬虫的相关概念
    Flask第十四篇- Flask-Session组件、WTForms组件、数据库连接池(POOL)
    Flask第十三篇- flask请求上下文源码解读、http聊天室单聊/群聊(基于gevent-websocket)
    Flask第十二篇- flask中的CBV、werkzeug+上下文初步解读、偏函数和线程安全
    Flask第十一篇装饰器的坑及解决办法、flask中的路由/实例化配置/对象配置/蓝图/特殊装饰器(中间件、重定义错误页面)
    Flask第十八篇 Flask-Migrate
    Flask第十七篇 Flask-Scrip
    Flask第十六篇 Flask-SQLAlchemy
    Flask第十篇 before_request after_request
  • 原文地址:https://www.cnblogs.com/wenming205/p/1237928.html
Copyright © 2011-2022 走看看