ASP.net gridview之性别
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 System.Data.SqlClient;
using MySql.Data.MySqlClient; public partial class GridView_分页_ : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["SortOrder"] = "stu_id";
ViewState["OrderDire"] = "ASC"; Bind();
}
}
public void Bind()
{
DropDownList ddl;
string sqlstr = "select * from t_student";
DataSet myds = DBHelper.SqlHelper.ExecuteDataSetText(sqlstr);
DataView view = myds.Tables[0].DefaultView;
string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
view.Sort=sort;
GridView1.DataSource=view; ////GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "stu_id" };//主键
GridView1.DataBind(); for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{ //当前页从那条开始
int page = GridView1.PageIndex;
int size=GridView1.PageSize;
int pageCount = page * size;
DataRowView mydrv = myds.Tables[0].DefaultView[pageCount+i];
if (Convert.ToString(mydrv["stu_sex"]).Trim() == "1")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
ddl.SelectedIndex = 0;
}
if (Convert.ToString(mydrv["stu_sex"]).Trim() == "0")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
ddl.SelectedIndex = 1;
}
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Bind();
}
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;
}
Bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;//把那一行设为编辑状态
Bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
Bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sqlstr = "update t_student set stu_code='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',stu_name='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',stu_sex='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "',age='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "',stu_dept='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim() + "',stu_admin='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.ToString().Trim() + "',stu_provinces='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[8].Controls[0])).Text.ToString().Trim() + "',stu_city='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[9].Controls[0])).Text.ToString().Trim() + "',stu_districts='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[10].Controls[0])).Text.ToString().Trim() + "' where stu_id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
DBHelper.SqlHelper.ExecteNonQueryText(sqlstr);
GridView1.EditIndex = -1;
Bind();
}
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;
Bind();
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox CheckBox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox2");
if (CheckBox3.Checked == true)
{
CheckBox.Checked = true;
}
else
{
CheckBox.Checked = false;
}
}
CheckBox4.Checked = false;
}
protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox CheckBox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox2");
if (CheckBox4.Checked == false)
{
CheckBox.Checked = true;
}
else
{
CheckBox.Checked = false;
}
}
CheckBox3.Checked = false;
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridView1.SelectedIndex = e.NewSelectedIndex;
int index = e.NewSelectedIndex;
string key = GridView1.DataKeys[index].Value.ToString();
CheckBox check = (CheckBox)GridView1.Rows[index].FindControl("CheckBox2");
check.Checked = true;
} public MySqlDataReader ddbind() { string sql = " select distinct stu_sex,case(stu_sex) when 1 then '男' else '女' end as stu_sex_ch from t_student";
return DBHelper.SqlHelper.ExecuteReaderText(sql, null);
}
}
<asp:DropDownList ID="DropDownList1" runat="server"
DataValueField="stu_sex" Height="19px" Width="67px" DataTextField="stu_sex_ch" DataSource="<%#ddbind() %>">
</asp:DropDownList>
ASP.net gridview之性别的更多相关文章
- Asp.net GridView 72般绝技
快速预览:GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠 ...
- 【DevExpress v17.2新功能预告】增强ASP.NET GridView的功能
在下一个主要版本v17.2中,我们将为DevExpress ASP.NET GridView添加一些优秀的新功能.在本文中为大家介绍的所有功能都可用于 GridView的ASP.NET WebForm ...
- Asp.net Gridview导出Excel
前台页面放一个GridView什么的就不说了,要注意的是在 <%@ Page Language="C#" AutoEventWireup="true" C ...
- asp.net gridview 鼠标悬浮提示信息
使用场景: gridview绑定数据,某列数据太多,故超过一定字符,隐藏起来,同时鼠标移到指定列显示其明细信息: 知识点: 1,oderListTbl_DataBound事件中,添加,oderList ...
- asp.net gridview动态添加列,并获取其数据;
1,绑定数据前先动态添加列,见方法CreateGridColumn(只在第一次加载动态添加): 2,gvlist_RowDataBound为对应列添加控件: 前台代码: <%@ Page Lan ...
- Asp.net GridView控件使用纪要
1:数据绑定 GridView 支持数据绑定的数据源格式比较多,例如可以使用ObjectDataSource绑定数据源, Dataset,datatable,List<T>等 2:列绑定 ...
- asp.net Gridview 的用法
留个档. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="Fa ...
- ASP.NET GridView HyperLinkField传值和取值【转】
来源:http://www.cnblogs.com/junjie94wan/archive/2011/08/17/2143623.html 经常做Winform程序,好久没有做WEB都有些生疏了,Gr ...
- asp.net - GridView根据linkButton值不同跳转不同页面
一,当前页面中,前台界面的主要代码: <asp:TemplateField HeaderText="姓名"> <ItemTemplate> <!--根 ...
随机推荐
- Thread-Safe Resource Manager
http://php.net/manual/en/internals2.memory.tsrm.php When PHP is built with Thread Safety enabled, th ...
- Yii2中数据过滤方案
1. 将数据赋值给model对象再通过model保存数据到数据库时有两种方法. 1) load()再save(). 这种可以通过$model->setScenario('test_scenari ...
- scala集合List和Set
一:List集合 1.创建 2.简单使用(两个部分) 3.Nill空集合 4.创建一个可变的list集合 二:Set 1.说明 无序,不重复 2.新建 3.可变
- 使用JMeter进行简单的压力测试
一.压力测试 顾名思义:压力测试,就是 被测试的系统,在一定的访问压力下,看程序运行是否稳定/服务器运行是否稳定(资源占用情况). 比如: 2000个用户同时到一个购物网站购物,这些用户打开页面的速 ...
- Servlet的历史与规范
http://blog.csdn.net/u010297957/article/details/51498018
- oracle not in,not exists,minus 数据量大的时候的性能问题
http://blog.csdn.net/greenappple/article/details/7073349/ 耗时 minus<not exists<not in
- C++ 中的sort排序用法
STL中就自带了排序函数sortsort 对给定区间所有元素进行排序 要使用此函数只需用#include <algorithm> sort即可使用,语法描述为:sort(begin,end ...
- Web 服务器 low bandth DOS attack
https://www.owasp.org/images/0/04/Roberto_Suggi_Liverani_OWASPNZDAY2010-Defending_against_applicatio ...
- http缓存之304 last-modified,cache-control:max-age,Etag等
因最近客户端慢的问题,系统分析了下http协议缓存问题.本文主要记录总结http缓存相关知识. 1. 讨论涉及的要点 访问返回类 > 访问返回200 OK > 访问返回200 (from ...
- Java 动态代理作用是什么?
Java 动态代理作用是什么? 1 条评论 分享 默认排序按时间排序 19 个回答 133赞同反对,不会显示你的姓名 Intopass 程序员,近期沉迷于动漫ING 133 人赞同 ① 首先你 ...