在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
前台.aspx 复制代码 代码如下: <asp:Label ID="tplb" runat="server" Text="总页数:"></asp:Label> <asp:Label ID="lblPageCount" runat="server" Text=""></asp:Label> <asp:Label ID="curLabel" runat="server" Text="当前页:"></asp:Label> <asp:Label ID="lblPage" Text="1" runat="server"></asp:Label> <asp:LinkButton ID="lblFirstButton" runat="server" OnClick="lblFirstButton_Click" >|<</asp:LinkButton> <asp:LinkButton ID="lblPreButton" runat="server" OnClick="lblPreButton_Click" ><</asp:LinkButton> <asp:LinkButton ID="lblNextButton" runat="server" OnClick="lblNextButton_Click" >></asp:LinkButton> <asp:LinkButton ID="lblLastButton" runat="server" OnClick="lblLastButton_Click" >>|</asp:LinkButton> <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 排序 =======自带分页 protected void FollowExamInfoGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) 选中Grid View 的实现 复制代码 代码如下: #region实现选中行 <SelectedRowStyle BackColor="AliceBlue" ForeColor="Gray" /> <asp:CommandField ShowSelectButton="True"/> if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onclick", "this.cells[0].childNodes[0].click()"); } protected void GridViewRegiment_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow row = GridViewRegiment.SelectedRow; int RegimentID = Convert.ToInt32(row.Cells[1].Text); Response.Redirect("UpdateRegimentation.aspx?RegimentID=" + RegimentID); } #endregion 显示颜色和删除 复制代码 代码如下: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { //int i; //for (i = 0; i < GridViewRegiment.Rows.Count; i++) //{ if (e.Row.RowType == DataControlRowType.DataRow) { //当有编辑列时,避免出错,要加的RowState判断 if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) { ((ImageButton)e.Row.Cells[2].FindControl("IBtndelete")).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:"" + e.Row.Cells[0].Text + ""吗?')"); } e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00A9FF'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E6F5FA'"); } //} } GridView空的处理 1 显示无表头的空纪录,EmptyDataText="没有记录" 2 显示表头的空纪录 复制代码 代码如下: DataTable dt = new DataTable(); dt = feibf.GetByPersonIDFollowExamInfo(PersonID); //查询指定人的随访信息记录 DataView dv = SortBindGrid(dt); if (dt.Rows.Count > 0) { FollowExamInfoGridView.DataSource = dv; FollowExamInfoGridView.DataBind(); } else { //添加新行显示表头 dt.Rows.Add(dt.NewRow()); FollowExamInfoGridView.DataSource = dt; FollowExamInfoGridView.DataBind(); //处理新行 int columnCount = FollowExamInfoGridView.Rows[0].Cells.Count; //清除掉该空行的全部单元格 FollowExamInfoGridView.Rows[0].Cells.Clear(); //新建单元格对象 FollowExamInfoGridView.Rows[0].Cells.Add(new TableCell()); //合并单元格 FollowExamInfoGridView.Rows[0].Cells[0].ColumnSpan = columnCount; //设置单元格提示内容 FollowExamInfoGridView.Rows[0].Cells[0].Style.Value = "text-align:center"; FollowExamInfoGridView.Rows[0].Cells[0].Text = "此人无随访信息"; } GridView 的导出 EnableEventValidation="false" 复制代码 代码如下: #region导出 public override void VerifyRenderingInServerForm(Control control) { } protected void BtnPrint_Click(object sender, EventArgs e) { Response.Clear(); Response.Buffer = true; Response.Charset = "GB2312"; Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls"); // 如果设置为GetEncoding("GB2312");导出的文件将会出现乱码!!! Response.ContentEncoding = System.Text.Encoding.UTF7; Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); this.AfficheGV.RenderControl(oHtmlTextWriter); Response.Output.Write(oStringWriter.ToString()); Response.Flush(); Response.End(); } #endregion ToolTip GridView详细信息的显示 后台 复制代码 代码如下: protected void AfficheGV_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) { 1 e.Row.Attributes.Add("onmouseover", "Tooltip('" +e.Row.Cells[0].Text.ToString()+ "','"+e.Row.Cells[1].Text.ToString()+"')"); 2 e.Row.Attributes.Add("onmouseover","javascript:Tooltip('e.Row.Cells[0].Text');"); 3 e.Row.Attributes.Add("onmouseover", "Tooltip('e.Row.Cells[0].Text')"); } } } #region自带编辑 #region样式的控制 以上是GridView控件的一些基础使用大全,希望对大家有所用处。 |
请发表评论