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之性别的更多相关文章

  1. Asp.net GridView 72般绝技

    快速预览:GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠 ...

  2. 【DevExpress v17.2新功能预告】增强ASP.NET GridView的功能

    在下一个主要版本v17.2中,我们将为DevExpress ASP.NET GridView添加一些优秀的新功能.在本文中为大家介绍的所有功能都可用于 GridView的ASP.NET WebForm ...

  3. Asp.net Gridview导出Excel

    前台页面放一个GridView什么的就不说了,要注意的是在 <%@ Page Language="C#" AutoEventWireup="true" C ...

  4. asp.net gridview 鼠标悬浮提示信息

    使用场景: gridview绑定数据,某列数据太多,故超过一定字符,隐藏起来,同时鼠标移到指定列显示其明细信息: 知识点: 1,oderListTbl_DataBound事件中,添加,oderList ...

  5. asp.net gridview动态添加列,并获取其数据;

    1,绑定数据前先动态添加列,见方法CreateGridColumn(只在第一次加载动态添加): 2,gvlist_RowDataBound为对应列添加控件: 前台代码: <%@ Page Lan ...

  6. Asp.net GridView控件使用纪要

    1:数据绑定 GridView 支持数据绑定的数据源格式比较多,例如可以使用ObjectDataSource绑定数据源, Dataset,datatable,List<T>等 2:列绑定 ...

  7. asp.net Gridview 的用法

    留个档. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="Fa ...

  8. ASP.NET GridView HyperLinkField传值和取值【转】

    来源:http://www.cnblogs.com/junjie94wan/archive/2011/08/17/2143623.html 经常做Winform程序,好久没有做WEB都有些生疏了,Gr ...

  9. asp.net - GridView根据linkButton值不同跳转不同页面

    一,当前页面中,前台界面的主要代码: <asp:TemplateField HeaderText="姓名"> <ItemTemplate> <!--根 ...

随机推荐

  1. angular路由 模块 依赖注入

    1.模块 var helloModule=angular.module('helloAngular',[]); helloModule.controller('helloNgCrtl',['$scop ...

  2. ElasticSearch返回不同的type的序列化

    总体思路是: 利用json序列化的别名方法,反序列化到不同的字段上: 因为别名方法不支持多个别名,所以不得不根据不同的type,定义了多套适配内容. 最终在属性上进行选择. 本示例ElasticSea ...

  3. Hire Me, Microsoft China

    为微软中国工作是一个愿望.对于其他的股票期权,令人难以置信的小吃店或很酷的工作室,引诱他们的可能性.很多人都想为微软中国工作,谁知道,也许你就是其中之一.这个博客是专门为在微软中国工作.做它的工作空缺 ...

  4. MYSQL相关完整笔记

    useradd mysql -s /sbin/nologin cat/etc/passwd | grep mysqlcat /etc/group | grep mysql 源目录 cd /usr/sr ...

  5. inline--行内元素

    其实在网页中有看不见的基线,就像作业本上面的一行一行的线,但是我们看不见. div是块状元素,独占一行,用div控制文字的颜色会使得文字换行,使用float可以改善,但是它不会浮在相应的位置: < ...

  6. vue 实现分转元的 过滤器

    1.啥也不说了直接上代码吧  使用起来超方便 Vue.filter('amount', function (number) { // var number = +val.replace(/[^\d.] ...

  7. MyBatis操作指南-与Spring集成(基于注解)

  8. Android中如何查看内存

    文章参照自:http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-a ...

  9. Elasticsearch之client源码简要分析

    问题 让我们带着问题去学习,效率会更高 1  es集群只配置一个节点,client是否能够自动发现集群中的所有节点?是如何发现的? 2  es client如何做到负载均衡? 3  一个es node ...

  10. Leetcode: Poor Pigs

    There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. Th ...