时间:2021-05-28
效果图:
功能简介:可使用上下键选中行,选中后点击修改,textbox获得gridview中的代码的数据。对你有帮助的话,请记得要点击“好文要顶”哦!!!不懂的,请留言。废话不多说了,贴码如下:
核心代码:
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;//請添加以下命名空間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設定樣式有用到 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) { //设置悬浮鼠标指针形状为"小手" 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(); } }}声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
Asp解析XML并分页显示,示例源码如下:复制代码代码如下:第一页>最后一页第一页上一页123456下一页>>最后一页第一页上一页下一页>>最后一页效果图(部分
使用vue编写的分页器组件,支持输入页码跳转,效果如图:1、点击前五页:2、点击中间部分页面3、点击第一页,上一页按钮失效,点击最后一页,下一页按钮失效组件调用
Asp.Net分页可以设置分页的首页、上一页、下一页、尾页在前台显示的链接文本。这里只是提及简单功能,深入研究剖析其原理就更得心应手了。//containerI
先来看看DEDECMS默认的TAG列表分页(5.6为例):第1页时:首页上一页123456下一页末页第3页时:首页上一页123456下一页末页分页连接方式和栏目
在.aspx页面里的代码复制代码代码如下:[ ][ ]第一页上一页下一页 最后一页 在.aspx.cs页面里