<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>网页查询</title>
<link href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<script src="http://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!-- HTML5 Shim 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<style>
* {
margin:0px;
padding:0px;
} .lab-a {
margin:20px auto; } </style>
</head>
<body>
<form id="form1" runat="server" class="form-horizontal"> <div class="form-group lab-a">
<asp:Label ID="Label1" runat="server" Text="标题:" style="margin-bottom:-30px;" class="col-sm-3 control-label "></asp:Label>
<div class="col-sm-10 col-sm-offset-3">
<asp:TextBox ID="TextBox1" runat="server" Height="30px" Width="271px" class="form-control"></asp:TextBox>
</div>
</div>
<div class="form-group ">
<div class="col-sm-10 col-sm-offset-3">
<label for="name">查询条件选择:</label>
<div class="lab-a ">
<label class="checkbox-inline">
<asp:CheckBox ID="CheckBox2" runat="server" /> 学生性别
</label> <label class="checkbox-inline">
<asp:CheckBox ID="CheckBox4" runat="server" /> 学生姓名
</label>
<label class="checkbox-inline">
<asp:CheckBox ID="CheckBox5" runat="server" />学生年龄
</label> </div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-10">
<asp:Button ID="Button1" runat="server" Text="查询" class="btn btn-primary" OnClick="Button1_Click1" />
<asp:Button ID="Button5" runat="server" Text="添加" class="btn btn-success" OnClick="Button5_Click" />
<asp:Button ID="Button2" runat="server" Text="修改" class="btn btn-warning" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="删除" class="btn btn-danger" OnClick="Button3_Click" /> <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager> </div> </div> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="126px" Width="855px" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal" AllowPaging="True" CssClass="table-hover table" PageSize="5" OnPageIndexChanging="GridView1_PageIndexChanging" OnDataBound="GridView1_DataBound" AllowSorting="True" OnSorting="GridView1_Sorting" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting" >
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="stu_id" HeaderText="学生编号" SortExpression="stu_id" />
<asp:BoundField DataField="stu_code" HeaderText="学生学号" />
<asp:BoundField DataField="stu_name" HeaderText="学生姓名" />
<asp:BoundField DataField="stu_sex" HeaderText="学生性别" />
<asp:BoundField DataField="age" HeaderText="学生年龄" />
<asp:BoundField DataField="stu_dept" HeaderText="学生系别" />
<asp:BoundField DataField="stu_admin" HeaderText="学生密码" />
<asp:BoundField DataField="stu_provinces" HeaderText="省" />
<asp:BoundField DataField="stu_city" HeaderText="市" />
<asp:BoundField DataField="stu_districts" HeaderText="县" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<PagerTemplate>
<asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
<asp:LinkButton ID="lbnFirst" runat="Server" Text="首页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First" ></asp:LinkButton>
<asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev" class="previous" ></asp:LinkButton>
<asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next" class="next"></asp:LinkButton>
<asp:LinkButton ID="lbnLast" runat="Server" Text="尾页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last" ></asp:LinkButton>
到第 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" ForeColor="Red" Height="19px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="70px"></asp:DropDownList> 页
</PagerTemplate>
<RowStyle BackColor="White" ForeColor="#333333" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel> </form>
</body>
</html>

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using DBHelper; public partial class Index : System.Web.UI.Page
{
Student stu_s = new Student(); protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["SortOrder"] = "stu_id";
ViewState["OrderDire"] = "ASC";
BindView();
}
} public void BindView()
{
string names = "";
if (!string.IsNullOrEmpty(this.TextBox1.Text)) {
names += " and stu_name like '" + this.TextBox1.Text + "%'"; }
DataView view=stu_s.GetTableSet(names);
string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
view.Sort = sort;
GridView1.DataSource = view;
GridView1.DataKeyNames = new string[] { "stu_id" };
GridView1.DataBind(); //GridView1.BottomPagerRow.Visible = true;
//GridViewRow pagerow = GridView1.BottomPagerRow; }
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindView();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow pagerRow = GridView1.BottomPagerRow; DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("DropDownList1"); GridView1.PageIndex = pageList.SelectedIndex;
BindView();
}
protected void GridView1_DataBound(object sender, EventArgs e)
{ //GridViewRow pagerRow = GridView1.BottomPagerRow;
//DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("DropDownList1");
//if (pageList != null)
//{ // for (int i = 0; i < GridView1.PageCount; i++)
// { // int pageNumber = i + 1;
// ListItem item = new ListItem(pageNumber.ToString()); // if (i == GridView1.PageIndex)
// {
// item.Selected = true;
// } // pageList.Items.Add(item); // } //} }
protected void Button1_Click(object sender, EventArgs e)
{ }
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
string sPage = e.SortExpression;
if (ViewState["SortOrder"].ToString() == sPage)
{
if (ViewState["OrderDire"].ToString() == "Desc")
ViewState["OrderDire"] = "ASC";
else
ViewState["OrderDire"] = "Desc";
}
else
{
ViewState["SortOrder"] = e.SortExpression;
}
BindView();
}
protected void Button1_Click1(object sender, EventArgs e)
{
//if (this.TextBox1.Text == "")
//{
// BindView();
//}
//else
//{
// string names = this.TextBox1.Text.Trim();
// DataView view = stu_s.GetTableViewString(names); // GridView1.DataSource = view;
// GridView1.DataKeyNames = new string[] { "stu_id" };
// GridView1.DataBind(); //}
BindView(); }
protected void Button5_Click(object sender, EventArgs e)
{
Response.Redirect("AddStudent.aspx");
}
protected void Button2_Click(object sender, EventArgs e)
{
string id="";
for (int i = 0; i < GridView1.Rows.Count - 1; i++) {
CheckBox ckb = (CheckBox)GridView1.Rows[i].FindControl("Checkbox1");
if (ckb.Checked == true) { id = GridView1.DataKeys[i].Value.ToString();
} }
Response.Redirect("AddStudent.aspx?id=" + id);
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from t_student where stu_id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
DBHelper.SqlHelper.ExecteNonQueryText(sqlstr);
Response.Write("<script>alert('删除成功')</script>");
GridView1.EditIndex = -1;
BindView();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[11].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:" + e.Row.Cells[3].Text + "吗?')");
} //////首先判断是否是数据行
////if (e.Row.RowType == DataControlRowType.DataRow)
////{
//// //当鼠标停留时更改背景色
//// e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
//// //当鼠标移开时还原背景色
//// e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
////} //如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
} }
protected void Button3_Click(object sender, EventArgs e)
{ string id = "";
for (int i = 0; i < GridView1.Rows.Count - 1; i++)
{
CheckBox ckb = (CheckBox)GridView1.Rows[i].FindControl("Checkbox1");
if (ckb.Checked == true)
{ id = GridView1.DataKeys[i].Value.ToString();
} }
int x = stu_s.GetDelStudent(id);
if (x > 0)
{
Response.Write("<script>alert('删除成功,当前删除值':" + id + ");</script>");
}
else { Response.Write("<script>alert('删除失败')</script>");
}
BindView();
}
}

  

ASP。net 之view的更多相关文章

  1. 【记录】ASP.NET MVC View 移动版浏览的奇怪问题

    ASP.NET MVC View 中的一段代码: <span id="span_Id">@Model.ID</span> 没什么问题吧,浏览器浏览正常,查看 ...

  2. ASP.Net MVC View

    ASP.Net MVC View(视图)   View视图职责是向用户提供界面.负责根据提供的模型数据,生成准备提供给用户的格式界面. 支持多种视图引擎(Razor和ASPX视图引擎是官方默认给出的, ...

  3. ASP.NET MVC View 和 Web API 的基本权限验证

    ASP.NET MVC 5.0已经发布一段时间了,适应了一段时间,准备把原来的MVC项目重构了一遍,先把基本权限验证这块记录一下. 环境:Windows 7 Professional SP1 + Mi ...

  4. ASP.NET MVC View中的标签(tag)

    在编辑View的时候会用到各种HTML标签,如<a>,<input>,<p>等待,这些标签在ASP.NET MVC中都有对应的编程语法,它叫Razor,它是帮助我们 ...

  5. ASP.NET MVC View使用Conditional compilation symbols

    由于View(.cshtml)的运行时编译关系,在项目级别中定义的symbols是无法被直接使用的.需要在Web.config中添加compilerOptions(在View目录下的Web.confi ...

  6. 移花接木:借助 IViewLocationExpander 更换 ASP.NET Core View Component 视图路径

    端午节在家将一个 asp.net 项目向 asp.net core 迁移时遇到了一个问题,用 view component 取代 Html.RenderAction 之后,运行时 view compo ...

  7. ASP.NET MVC View向Controller传值方式总结

    1:QueryString传值1)也可以使用new{}来为form的action增加querystring2)在controler里使用Request.QueryString["word&q ...

  8. ASP.NET MVC View向Controller提交数据

    我们知道使用MVC的一个很重的的用途就是把Controller和View之间进行解耦,通过控制器来调用不同的视图,这就注定了Controller和View之间的传值是一个很重的知识点,这篇博文主要解释 ...

  9. probing privatePath如何作用于ASP.NET MVC View

    当View上using一些从probing privatePath加载的程序集,运行时会提示无法找到对应程序集. <runtime> <assemblyBinding xmlns=& ...

  10. ASP.NET-前台view返回model集合

    有时操作列表的时候想一次提交一个model集合,这样后台controller直接接受后就可以直接进行操作了,不用使用js,比较方便,也体现了MVC的Binding模式的优势,方法如下: 准备: 1.两 ...

随机推荐

  1. 【转】监听按钮除OnClick外其他事件的方法,附简易改编的UIButton类

    http://lib.csdn.net/article/unity3d/38463 作者:IceFantasyLcj 大家好,我是雨中祈雨.一直以来,CSDN都是我最好的编程助手.这是我在CSDN的第 ...

  2. 解决mysql数据库插入中文字段时出现??? 的问题

    1.检查并修改mysql的my.ini的配置文件   default-character-set=utf8 2.建立数据库是要指定字符集   create database mydb default ...

  3. ZTE交换路由设备配置的备份与恢复

    一.TFTP服务器搭建 使用用户计算机搭建TFTP服务器,交换路由设备作为TFTP客户端. 运行TFTPServer.exe,该程序所在的目录为TFTP的根目录. 请保证您的TFTP可以Ping通所要 ...

  4. 开发者所需要知道的 iOS 10 SDK 新特性

    转自:https://onevcat.com/2016/06/ios-10-sdk/ 写的很好啊.哈哈哈 总览 距离 iPhone 横空出世已经过去了 9 个年头,iOS 的版本号也跨入了两位数.在我 ...

  5. ueditor的模板功能

    ~~项目临时发现kindeditor比ueditor更好用~~ 不过还是回来把ueditor的学习,加一个书签标明一下阶段. 下面写一下ueditor的模板功能,即修改模板,使ueditor自动生成想 ...

  6. chrome中hack解决input:-webkit-autofill自定义样式

    在使用chrome浏览器设计网页时,想将input背景改成透明,也就是 background-color:transparent; 可是效果并不如人意 hack方法: input:-webkit-au ...

  7. LightOj 1298 - One Theorem, One Year(DP + 欧拉)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...

  8. flask-sqlalchemy、pytest 的单元测试和事务自动回滚

    flask-sqlalchemy.pytest 的单元测试和事务自动回滚 使用 flask-sqlalchemy 做数据库时,单元测试可以帮助发现一些可能意想不到的问题,像 delete-cascad ...

  9. Lua屏蔽对象方法和恢复的方法

    背景 对于OO思想实现的类, 对于某些场景需要屏蔽某些方法, 不让调用.过了这段场景, 就恢复这些类的方法, 可以调用. 例如: 工厂具有开工方法, 但是在晚上不允许开工, 所有在晚上这段时间, 见开 ...

  10. memcached SASLAUTH 启动

    1.环境描述: Linux 服务器,memcached1.4.5 登录linux的用户名tuxedo,密码tuxedo 2.启动memcached sasl认证 p.p1 { margin: 0.0p ...