ASP。net 之view
<%@ 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的更多相关文章
- 【记录】ASP.NET MVC View 移动版浏览的奇怪问题
ASP.NET MVC View 中的一段代码: <span id="span_Id">@Model.ID</span> 没什么问题吧,浏览器浏览正常,查看 ...
- ASP.Net MVC View
ASP.Net MVC View(视图) View视图职责是向用户提供界面.负责根据提供的模型数据,生成准备提供给用户的格式界面. 支持多种视图引擎(Razor和ASPX视图引擎是官方默认给出的, ...
- ASP.NET MVC View 和 Web API 的基本权限验证
ASP.NET MVC 5.0已经发布一段时间了,适应了一段时间,准备把原来的MVC项目重构了一遍,先把基本权限验证这块记录一下. 环境:Windows 7 Professional SP1 + Mi ...
- ASP.NET MVC View中的标签(tag)
在编辑View的时候会用到各种HTML标签,如<a>,<input>,<p>等待,这些标签在ASP.NET MVC中都有对应的编程语法,它叫Razor,它是帮助我们 ...
- ASP.NET MVC View使用Conditional compilation symbols
由于View(.cshtml)的运行时编译关系,在项目级别中定义的symbols是无法被直接使用的.需要在Web.config中添加compilerOptions(在View目录下的Web.confi ...
- 移花接木:借助 IViewLocationExpander 更换 ASP.NET Core View Component 视图路径
端午节在家将一个 asp.net 项目向 asp.net core 迁移时遇到了一个问题,用 view component 取代 Html.RenderAction 之后,运行时 view compo ...
- ASP.NET MVC View向Controller传值方式总结
1:QueryString传值1)也可以使用new{}来为form的action增加querystring2)在controler里使用Request.QueryString["word&q ...
- ASP.NET MVC View向Controller提交数据
我们知道使用MVC的一个很重的的用途就是把Controller和View之间进行解耦,通过控制器来调用不同的视图,这就注定了Controller和View之间的传值是一个很重的知识点,这篇博文主要解释 ...
- probing privatePath如何作用于ASP.NET MVC View
当View上using一些从probing privatePath加载的程序集,运行时会提示无法找到对应程序集. <runtime> <assemblyBinding xmlns=& ...
- ASP.NET-前台view返回model集合
有时操作列表的时候想一次提交一个model集合,这样后台controller直接接受后就可以直接进行操作了,不用使用js,比较方便,也体现了MVC的Binding模式的优势,方法如下: 准备: 1.两 ...
随机推荐
- laravel DB事物
public function store(Request $request, $id) { $externalAccount = ExternalAccounts::find($id); DB::b ...
- 【Git学习笔记】远程仓库
第一种情景:本地初始化一个Git仓库后,接着又在github上创建了一个Git仓库,现在要让这两个仓库进行远程同步. 1. 关联本地仓库就和远程仓库 $ git remote add origin ...
- angular路由 模块 依赖注入
1.模块 var helloModule=angular.module('helloAngular',[]); helloModule.controller('helloNgCrtl',['$scop ...
- [转载]ERP实施40问 60分钟外行变专家
http://www.chinaodoo.net/thread-389-1-1.html 在多年的实践中,结合自身经验和多年的理论积累,总结出有关ERP实施的最关键的40个问题,以问答的形式,让您在最 ...
- linq join的lambda写法
var query = _db.Bank_CommercialOpus .Join(_db.Bank_Opus, s => s.OpusID, Opus => Opus.ID, (s, O ...
- 针对功能权限(url访问)如何避免越权访问
你可以用request获得之前的页面路径:Request.getHeader("Referer");然后你可以判断一下,这个是字符串类型的. 如果是需要登录的,你可以从sessio ...
- QFileSystemModel
#include "dialog.h" #include "ui_dialog.h" Dialog::Dialog(QWidget *parent) : QDi ...
- SQL CURSOR
SET NOCOUNT ON; DECLARE @vendor_id int, @vendor_name nvarchar(50), @message varchar(80), @produc ...
- AFNetworking 2.0指北
AFNetworking 2.0 来了 SEP 30TH, 2013 前几天 Mattt 发布了 AFNetworking 2.0,我的一个最大感慨就是,他怎么那么高产? 关于 Mattt Mattt ...
- git操作的常用命令
git remote show origin 查看git远程信息git remote set-url origin git@gitlab.staff.xdf.cn:woxue/woxueadmin.g ...