datagrid 分頁及隱藏指定列再以及滑鼠動作(換背景)

來源:互聯網
上載者:User

當使用分頁功能的時候,點下頁就觸發PageIndexChanged事件,所以要在這下面加點東東!!

private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  {
   this.DataGrid1.CurrentPageIndex=e.NewPageIndex;//判斷當前頁碼是多少?並傳入下頁的頁碼
   this.binder();//這個是做了一個Binder 方法,這裡只是調用綁定
  }

  private void LinkButton1_Click(object sender, System.EventArgs e)
  {
  int i=Convert.ToInt32(this.TextBox1.Text);//這個列是從TextBox1傳入的
   this.DataGrid1.Columns[i].Visible=false;
   this.binder();
  }
  private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {//注意賦值時的大小寫
   if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)//選擇只是內容項(出去頭腳)加指令碼
   {
   e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");//滑鼠移至上方,讀取背景色,再把新色換成#6699ff
   e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c;");//滑鼠離開,把背景給換回去
   }
  }

如果你不是很無聊的話,最好把datagrid的高和寬取消了,只是單獨給裡面的項設定高度或者寬度,否則會出現一些地球人都不想看見的問題!

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.