濮阳杆衣贸易有限公司

主頁 > 知識庫 > asp.net gridview分頁:第一頁 下一頁 1 2 3 4 上一頁 最末頁

asp.net gridview分頁:第一頁 下一頁 1 2 3 4 上一頁 最末頁

熱門標(biāo)簽:電銷語音機(jī)器人型號參數(shù) 征途美甲店地圖標(biāo)注 400電話如何申請取消 柳州電銷機(jī)器人公司 百度地圖怎樣做地圖標(biāo)注 浦發(fā)電話機(jī)器人提醒還款 太原400電話上門辦理 昆明語音電銷機(jī)器人價格 騰訊地圖標(biāo)注手機(jī)

效果圖:

功能簡介:可使用上下鍵選中行,選中后點擊修改,textbox獲得gridview中的代碼的數(shù)據(jù)。對你有幫助的話,請記得要點擊“好文要頂”哦?。?!不懂的,請留言。廢話不多說了,貼碼如下:

head runat="server">
 title>GridView分頁/title>
 script type="text/javascript">
  var currentRowId = 0;
  var styleName = "";
  function SelectRow(ev, strGvName) {
   var e = window.event || ev;
   var keyCode = -1;
   if (e.which == null)
    keyCode = e.keyCode; // IE 
   else
    if (e.which > 0)
    keyCode = e.which; // All others 
   if (keyCode == 40)
    MarkRow(currentRowId + 1, strGvName);
   if (keyCode == 38) {
    MarkRow(currentRowId - 1, strGvName);
   }

   document.getElementById("NUM").value = currentRowId;
  }
  function MarkRow(rowId, strGvName) {
   var Grid = document.getElementById(strGvName);
   var rowCount = Grid.rows.length;
   if (document.getElementById(strGvName + rowId) == null)
    return;
   if (rowId == rowCount) {
    return;
   }
   if (document.getElementById(strGvName + currentRowId) != null)
    document.getElementById(strGvName + currentRowId).style.backgroundColor = styleName;
   currentRowId = rowId;
   styleName = document.getElementById(strGvName + rowId).style.backgroundColor;
   document.getElementById(strGvName + rowId).style.backgroundColor = 'red';
   var obj = document.getElementById(strGvName);
   obj.rows[rowId].cells[0].focus();
   document.getElementById("NUM").value = currentRowId;

  }
 /script>

 style type="text/css">
  .hidden
  {
   display: none;
  }
 /style>
/head>

核心代碼:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;//請?zhí)砑右韵旅臻g
using System.Data;
using System.Drawing;

public partial class _Default : System.Web.UI.Page
{
 SqlConnection con = new SqlConnection("Server=SERVER\\xxx;Database=xxxx;User ID=xx;Pwd=xx;");
 private int _i = 0;//定義變量 ,查詢 Grid設(shè)定樣式有用到
 protected void Page_Load(object sender, EventArgs e)
 {
  if (!Page.IsPostBack)
  {
   getBind();
  }
 }
 protected void getBind()
 {
  string str = "select * from im01";
  DataSet ds = new DataSet();
  SqlDataAdapter da = new SqlDataAdapter(str, con);
  da.Fill(ds);
  DataTable dt = ds.Tables[0];
  gvData.DataSource = dt;
  gvData.DataBind();
 }
 protected void gvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {

 }
 protected void gvData_RowCreated(object sender, GridViewRowEventArgs e)
 {
  if (e.Row.RowType == DataControlRowType.Pager)
  {
   Label label_Index = new Label();
   LinkButton Button_IndexFirst = new LinkButton();
   LinkButton Button_IndexLast = new LinkButton();
   LinkButton Button_IndexNext = new LinkButton();
   LinkButton Button_IndexPrevious = new LinkButton();

   Button_IndexFirst.Text = "第一頁 ";
   Button_IndexFirst.CommandName = "first";
   Button_IndexFirst.ForeColor = Color.Blue;
   Button_IndexFirst.Click += new EventHandler(PageButtonClick);

   Button_IndexNext.Text = " 下一頁 ";
   Button_IndexNext.CommandName = "next";
   Button_IndexNext.ForeColor = Color.Blue;

   Button_IndexNext.Click += new EventHandler(PageButtonClick);

   Button_IndexPrevious.Text = "前一頁 ";
   Button_IndexPrevious.CommandName = "previous";
   Button_IndexPrevious.ForeColor = Color.Blue;
   Button_IndexPrevious.Click += new EventHandler(PageButtonClick);

   Button_IndexLast.Text = "最末頁 ";
   Button_IndexLast.CommandName = "last";
   Button_IndexLast.ForeColor = Color.Blue;
   Button_IndexLast.Click += new EventHandler(PageButtonClick);

   e.Row.Controls[0].Controls[0].Controls[0].Controls[0].Controls.AddAt(0, (Button_IndexFirst));
   e.Row.Controls[0].Controls[0].Controls[0].Controls[0].Controls.AddAt(1, (Button_IndexPrevious));

   int controlTmp = e.Row.Controls[0].Controls[0].Controls[0].Controls.Count - 1;
   e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(Button_IndexNext);
   e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(Button_IndexLast);
  }
 }
 protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
 {
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
   //設(shè)置懸浮鼠標(biāo)指針形狀為"小手" 
   e.Row.Attributes["style"] = "Cursor:hand";
  }
  string strGvName = "gvData";
  e.Row.Attributes.Add("id", strGvName + _i.ToString());
  e.Row.Attributes.Add("onKeyDown", "SelectRow(event,'" + strGvName + "');");
  e.Row.Attributes.Add("onClick", "MarkRow(" + _i.ToString() + ",'" + strGvName + "');");
  e.Row.Attributes.Add("tabindex", "0");
  _i++;
 }
 protected void PageButtonClick(object sender, EventArgs e)
 {
  LinkButton clickedButton = ((LinkButton)sender);
  if (clickedButton.CommandName == "first")
  {
   gvData.PageIndex = 0;
  }
  else if (clickedButton.CommandName == "next")
  {
   if (gvData.PageIndex  gvData.PageCount - 1)
   {
    gvData.PageIndex += 1;
   }
  }
  else if (clickedButton.CommandName == "previous")
  {
   if (gvData.PageIndex >= 1)
   {
    gvData.PageIndex -= 1;
   }
  }
  else if (clickedButton.CommandName == "last")
  {
   gvData.PageIndex = gvData.PageCount - 1;
  }
  getBind();
 } 
 //修改
 protected void btnUpd_Click(object sender, EventArgs e)
 {
  int intNum = 0;
  if (this.NUM.Text == "" || this.NUM.Text == "0")
  {
   Response.Write("script type=\"text/javascript\">alert('請先查詢並選擇一筆資料!')/script>");
   return;
  }
  else
  {
   intNum = Convert.ToInt16(this.NUM.Text) - 1;
   tbValue.Text = this.gvData.Rows[intNum].Cells[1].Text.ToString();
  }
 }
}
您可能感興趣的文章:
  • asp.net中的GridView分頁問題
  • Android入門之ActivityGroup+GridView實現(xiàn)Tab分頁標(biāo)簽的方法
  • GridView分頁的實現(xiàn)以及自定義分頁樣式功能實例
  • Android中實現(xiàn)多行、水平滾動的分頁的Gridview實例源碼
  • Asp.net GridView使用大全(分頁實現(xiàn))
  • GridView分頁的實現(xiàn)(通用分頁模板)
  • AspNetPager+GridView實現(xiàn)分頁的實例代碼
  • asp.net中g(shù)ridview的查詢、分頁、編輯更新、刪除的實例代碼
  • GridView高效分頁和搜索功能的實現(xiàn)代碼
  • 解析GridView自帶分頁及與DropDownList結(jié)合使用

標(biāo)簽:張家界 新疆 德陽 白山 江蘇 陽泉 天門 蘭州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net gridview分頁:第一頁 下一頁 1 2 3 4 上一頁 最末頁》,本文關(guān)鍵詞  asp.net,gridview,分頁,第,一頁,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net gridview分頁:第一頁 下一頁 1 2 3 4 上一頁 最末頁》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net gridview分頁:第一頁 下一頁 1 2 3 4 上一頁 最末頁的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    台东市| 攀枝花市| 沐川县| 余庆县| 阳山县| 宁海县| 玉树县| 修武县| 宝山区| 临城县| 龙川县| 奉化市| 株洲市| 克什克腾旗| 正宁县| 科技| 新沂市| 夏津县| 个旧市| 大同县| 根河市| 乾安县| 运城市| 抚远县| 吐鲁番市| 大同县| 达孜县| 尼玛县| 股票| 公安县| 敖汉旗| 高州市| 张掖市| 阿巴嘎旗| 桐乡市| 鹤庆县| 东城区| 井陉县| 东山县| 桂东县| 夹江县|