<%@ 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. [flex布局]-flex教程

    简介:2009年,W3C提出了一种新的方案----Flex布局,可以简便.完整.响应式地实现各种页面布局.目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能. Flex布局是什 ...

  2. QHash

    #include <QCoreApplication> #include<QHash> #include<QDebug> int main(int argc, ch ...

  3. vuejsLearn---通过手脚架快速搭建一个vuejs项目

    开始快速搭建一个项目 通过Webpack + vue-loader 手脚架 https://github.com/vuejs-templates/webpack 按照它的步骤一步一步来 $ npm i ...

  4. angularJs之定时器

    $timeout 服务 AngularJS $timeout 服务对应了 JS window.setTimeout 函数. 实例 两秒后显示信息: var app = angular.module(' ...

  5. iOS JavaScriptCore与H5交互时出现异常提示

    在利用JavaScriptCore与H5交互时出现异常提示: This application is modifying the autolayout engine from a background ...

  6. 使用 apache2 + `mod_proxy_uwsgi` + uwsgi + upstart 部署

    使用 apache2 + mod_proxy_uwsgi + uwsgi + upstart 部署 网上运行 python wsgi 的应用时,大部分的资料都是使用 nginx .uwsgi ,很少资 ...

  7. MySQL的几个概念:主键,外键,索引,唯一索引

    概念: 主键(primary key) 能够唯一标识表中某一行的属性或属性组.一个表只能有一个主键,但可以有多个候选索引.主键常常与外键构成参照完整性约束,防止出现数据不一致.主键可以保证记录的唯一和 ...

  8. !+"\v1" 能判断浏览器类型吗?

    我在 http://www.iefans.net/ie-setattribute-bug/ 中看到如此判断是否是IE,if(!+"\v1"){IE代码}else{其他浏览器代码}, ...

  9. CentOS6.6安装vmware workstation报错

    本人系统用的是centos6.6,安装了vmware workstation,启动后一直如下图报错,相关内核已经安装了的,哪位前辈如果解决过这样的问题,麻烦指点指点,小弟在此先谢过了.

  10. 如何创建一个简单的C++同步锁框架(译)

    翻译自codeproject上面的一篇文章,题目是:如何创建一个简单的c++同步锁框架 目录 介绍 背景 临界区 & 互斥 & 信号 临界区 互斥 信号 更多信息 建立锁框架的目的 B ...