ASP.NET GridView使用代码总结

--注:由于是代码的总结,所以文字比较少。

前台

<asp:Label ID="tplb" runat="server" Text="总页数:"></asp:Label><asp:Label ID="lblPageCount"
                               runat="server" Text=""></asp:Label>&nbsp;&nbsp;
                             <asp:Label ID="curLabel" runat="server" Text="当前页:"></asp:Label><asp:Label ID="lblPage" Text="1"
                               runat="server"></asp:Label>&nbsp;
                             <asp:LinkButton ID="lblFirstButton" runat="server" OnClick="lblFirstButton_Click" >|&lt;</asp:LinkButton>&nbsp;
                             <asp:LinkButton ID="lblPreButton" runat="server" OnClick="lblPreButton_Click" >&lt;</asp:LinkButton>&nbsp;
                             <asp:LinkButton ID="lblNextButton" runat="server" OnClick="lblNextButton_Click" >&gt;</asp:LinkButton>&nbsp;
                             <asp:LinkButton ID="lblLastButton" runat="server" OnClick="lblLastButton_Click" >&gt;|</asp:LinkButton>&nbsp;
                             <asp:DropDownList ID="ddlPage" runat="server" Width="40px" AutoPostBack="True"
                               OnSelectedIndexChanged="ddlPage_SelectedIndexChanged">
                               <asp:ListItem>10</asp:ListItem>
                               <asp:ListItem>15</asp:ListItem>
                               <asp:ListItem>20</asp:ListItem>
                               <asp:ListItem>30</asp:ListItem>
                             </asp:DropDownList>
                             <asp:Label ID="PageSizeLabel" runat="server" Text="条/页">
</asp:Label>

后台

#region分页

protected void BindFollowExamInfoGridView(int PersonID)
   {
     int currentpage = Convert.ToInt32(lblPage.Text);
     DataTable dt = new DataTable();
     dt = feibf.GetByPersonIDFollowExamInfo(PersonID); //查询指定人的随访信息记录
     if (dt.Rows.Count > 0)
     {
       FollowExamInfoGridView.DataSource = dt;
       FollowExamInfoGridView.DataBind();
       PagedDataSource ps = new PagedDataSource();
       ps.DataSource = dt.DefaultView;
       ps.AllowPaging = true;
       ps.PageSize = Convert.ToInt32(ddlPage.SelectedValue);
       lblPageCount.Text = ps.PageCount.ToString();
       this.lblPreButton.Enabled = true;
       this.lblNextButton.Enabled = true;
       ps.CurrentPageIndex = currentpage - 1;
       if (currentpage == 1)
       {
         this.lblPreButton.Enabled = false;
         this.lblFirstButton.Enabled = false;
       }
       else
       {
         this.lblPreButton.Enabled = true;
         this.lblFirstButton.Enabled = true;
       }
       if (currentpage == ps.PageCount)
       {
         this.lblNextButton.Enabled = false;
         this.lblLastButton.Enabled = false;
       }
       else
       {
         this.lblNextButton.Enabled = true;
         this.lblLastButton.Enabled = true;
       }
       FollowExamInfoGridView.DataSource = ps;
       FollowExamInfoGridView.DataBind();
     }

   }
   protected void lblPreButton_Click(object sender, EventArgs e)
   {
     this.lblPage.Text = Convert.ToString(Convert.ToUInt32(lblPage.Text) - 1);
     BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"]));
   }
   protected void lblNextButton_Click(object sender, EventArgs e)
   {
     this.lblPage.Text = Convert.ToString(Convert.ToUInt32(lblPage.Text) + 1);
     BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"]));
   }
   protected void lblFirstButton_Click(object sender, EventArgs e)
   {
     this.lblPage.Text = "1";
     BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"]));
   }
   protected void lblLastButton_Click(object sender, EventArgs e)
   {
     this.lblPage.Text = lblPageCount.Text;
     BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"]));
   }
   protected void ddlPage_SelectedIndexChanged(object sender, EventArgs e)
   {
     lblPage.Text = "1";
     BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"]));
   }
#endregion

时间: 2024-09-08 11:52:00

ASP.NET GridView使用代码总结的相关文章

asp.net gridview实现全选,反选与删除记录的操作代码_实用技巧

gridview全选操作 复制代码 代码如下: 'columns'=>array( array( 'class'=>'CCheckBoxColumn', //'header'=>'全选', //'value'=>'$data->id', //'checked'=>'true', 'htmlOptions'=>array( 'width'=>'30', 'style'=>'text-align:center', ), ), 复制代码 代码如下: <

asp.net gridview 问题

问题描述 asp.net gridview 问题 asp:TemplateField 详细 图书编号 图书名 管理编号 详细 /asp:TemplateField /asp:GridView 报错如下DataBinding:"System.Data.DataRowView"不包含名为"BookID"的属性.]????这是后台代码public partial class BookSearch : System.Web.UI.Page{protected void Pa

asp.net gridview checkbox checked值取不到

问题描述 asp.net gridview checkbox checked值取不到 需要选择线上单号后,再弹框选择明细.问题是我勾选的checkbox的checked值一直都是false. 在!IsPostBack绑定数据时,是能选择到checkbox的值.但是更新数据再绑定后就选择不了. 这个是什么原因,有什么方法可以解决这个问题 <%@ Register src="OrderGoods.ascx" tagname="myuc4" tagprefix=&q

asp.net GridView中使用RadioButton单选按钮的方法_实用技巧

本文实例讲述了asp.net GridView中使用RadioButton单选按钮的方法.分享给大家供大家参考,具体如下: 在GridView里做单选按钮,我用了三种方法 第一种方法:在GridView的模版列里加服务器端控件RadioButton,使用js控制单选 使用模版列里加RadioButton <script type="text/javascript"> function setRadio(nowRadio) { var myForm,objRadio; myF

ASP.NET GridView中加入RadioButton不能单选的解决方案_实用技巧

 今天开发碰见一个问题,就是当GridView中加入一个包含RadioButton的模板列,结果一运行.....天啊,单选按钮可以多选了! 囧啊!为了演示一下我今天的错误我还是模拟一个功能场景吧,我要实现的功能是显示一个包含单选按钮的学生信息列表,选择一行后将详细信息显示出来~! 1.问题展现 ①首先准备一个GridView用来展示学生的基本信息与最重要的单选按钮,代码如下: <asp:GridView ID="GridView1" runat="server"

如何用jQuery实现ASP.NET GridView折叠伸展效果_jquery

今天做静态页面时有一个需求,就是页面上有一组两个选项的单选按钮和一个有6行的列表(该列表用Table标签实现,不是DIV),当选择单选按钮的选项一时,列表的前三条信息显示后三条信息隐藏,当选择单选按钮的选项二时,列表的前三条信息隐藏后三条信息显示.那么就牵扯出我们今天的话题拉,如何实现呢?实现后该实现还能应用到哪些场景? 1.第一反应的解决方案 碰到这个需求后,我第一反应就是很简单啊,分别用两个DIV将前三个Table中的TR标签与后三个TR标签包起来,然后通过JS控制DIV的显示. 第一步:使

asp.net gridview 72般绝技第1/2页_实用技巧

GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠标移到GridView某一行时改变该行的背景色方法一鼠标移到GridView某一行时改变该行的背景色方法二GridView实现删除时弹出确认对话框GridView实现自动编号GridView实现自定义时间货币等字符串格式GridView实现用"..."代替超长字符串GridView一般换行与强制换行

ASP.NET GridView的Bootstrap分页样式_实用技巧

本文实例为大家分享了GridView的Bootstrap分页样式,供大家参考,具体内容如下 Revenue.cs收入类,包括实体模型和业务逻辑 public class Revenue { public Revenue(string country, string revenue, string salesmanager, string year) { this.country = country; this.revenue = revenue; this.salesmanager = sale

asp.net GridView中CheckBox复选框(兼容FireFox)

在Asp.net中,可以通过模板列,在Gridview中实现CheckBox列的实现,相关的代码并不复杂,你可以参考这里,我抽取的部分代码如下:  代码如下 复制代码 <script language="javascript" type="text/javascript">    function selectAll(obj)    {         var theTable  = obj.parentElement.parentElement.par