• DataGrid常用小技巧


    当鼠标经过某一行时,使其突出显示,增加视觉效果,代码如下:
    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
       {
        e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#9CCBF7'");
        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

       }

    鼠标经过的行颜色为#9CCBF7,鼠标移开是又变回原来颜色,这里用c先保存原来的颠值!

    以上代码放在ItemDataBind事件中即可

    datagrid删除确认

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
       LinkButton mydel=(LinkButton)e.Item.FindControl ("btndel");
       if(mydel!=null)
       {
        mydel.Attributes .Add ("onclick","return confirm('确认删除吗?');");
       }
      }

    datagrid排序

    private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
      {
       DataSet ds=new DataSet();
       ds=DB.getdataset ("select * from mytab");
       DataView dv=ds.Tables [0].DefaultView ;
       dv.Sort=e.SortExpression ;
       DataGrid1 .DataSource =dv;
       DataGrid1 .DataBind ();
      
      }

    实现双向排序...

    if(ViewState["order"]==null)
       {
        ViewState["order"]="asc";
       }
       else
       {
        if(ViewState["order"].ToString ()=="asc")
        {
         ViewState["order"]="desc";

        }
        else
        {
         ViewState["order"]="asc";
        }

       }
       SqlConnection mycon=DB.creatcon ();
       SqlDataAdapter da=new SqlDataAdapter ("select * from student order by studentid desc ",mycon);
       DataSet ds=new DataSet() ;
       da.Fill (ds,"tabnew");
       DataView dv=ds.Tables [0].DefaultView ;
       dv.Sort =e.SortExpression+" "+ViewState["order"].ToString();
       DataGrid1.DataSource =dv;
       DataGrid1 .DataBind ();

  • 相关阅读:
    Proximal Algorithms 5 Parallel and Distributed Algorithms
    Proximal Algorithms 4 Algorithms
    Proximal Algorithms 3 Interpretation
    Proximal Algorithms 2 Properties
    Proximal Algorithms 1 介绍
    matplotlib 高阶之Transformations Tutorial
    matplotlib 高阶之patheffect (阴影,强调)
    matplotlib 高阶之path tutorial
    Django Admin Cookbook-19如何在管理后台中一个模型只允许创建一个对象
    Django Admin Cookbook-18如何限制对Django Admin管理部分功能的使用
  • 原文地址:https://www.cnblogs.com/chy710/p/550090.html
Copyright © 2020-2023  润新知