asp.net2.0 GridView的整理使用
来源:互联网 发布:巨潮数据库 编辑:程序博客网 时间:2024/05/21 07:47
<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<meta http-equiv="Cache-Control"content="no-cache, must-revalidate"/>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">...
function ButtonSelect()
...{
var chkall= document.all["chkAll"];
if(chkall.checked==false)
...{
chkall.setAttribute("checked","true");
}
else
...{
chkall.checked = false;
}
AllSelect();
}
function AllSelect()
...{
var len=document.form1.elements.length;
var i;
var chkall= document.all["chkAll"];
if (chkall.checked == true)
...{
for (i=0;i<len;i++)
...{
if (document.form1.elements[i].type=="checkbox")
...{
document.form1.elements[i].checked=true;
}
}
}
else
...{
for (i=0;i<len;i++)
...{
if (document.form1.elements[i].type=="checkbox")
...{
document.form1.elements[i].checked=false;
}
}
}
}
var k = <%=num%>
function checkgou()
...{
var chkall= document.all["chkAll"];
var len=document.form1.elements.length;
var i;
var j=0;
for (i=0;i<len;i++)
...{
if (document.form1.elements[i].type=="checkbox")
...{
if (document.form1.elements[i].checked == true)
...{
j++;
}
}
}
if (j==k) ...{
chkall.checked = true;
}
//window.alert(len);
}
</script>
</head>
<body onload="checkgou()">
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Height="200px"
Width="700px" CaptionAlign="Left" AllowPaging="True" AllowSorting="True" OnSorting="GridView1_Sorting" HeaderStyle-Font-Underline="true" OnRowCreated="GridView1_RowCreated">
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<RowStyle BackColor="White" ForeColor="#003399" Font-Size="Small" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" Font-Size="Small" Height="20px" Font-Underline="True" HorizontalAlign="Center" VerticalAlign="Middle" />
<EditRowStyle Font-Size="Small" Height="20px" HorizontalAlign="Center" />
<AlternatingRowStyle Font-Size="Small" ForeColor="#00C000" HorizontalAlign="Center" />
<PagerSettings Visible="False" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input id="chkAll" onclick="AllSelect()" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CHK" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" BackColor="#E0E0E0" BorderStyle="Groove"
BorderWidth="1px" CommandArgument="first" ForeColor="Red" Text="首页" OnClick="PageChange_Click" />
<asp:Button ID="Button2" runat="server" BackColor="#E0E0E0" BorderStyle="Groove"
BorderWidth="1px" CommandArgument="prv" ForeColor="Red" Text="上一页" OnClick="PageChange_Click" />
<asp:Button ID="Button3" runat="server" BackColor="#E0E0E0" BorderStyle="Groove"
BorderWidth="1px" CommandArgument="next" ForeColor="Red" Text="下一页" OnClick="PageChange_Click" />
<asp:Button ID="Button4" runat="server" BackColor="#E0E0E0" BorderStyle="Groove"
BorderWidth="1px" CommandArgument="last" ForeColor="Red" Text="尾页" OnClick="PageChange_Click" />
<asp:Label ID="Label1" runat="server" Text="Label" Width="350px"></asp:Label>
<asp:TextBox ID="sorttext" runat="server" Visible="False"></asp:TextBox><br />
<input id="Button6" type="button" onclick="ButtonSelect()" value="全选" />
<asp:Button ID="Button5" runat="server" BackColor="#FFC0FF" BorderColor="#00C000"
BorderStyle="Solid" BorderWidth="1px" OnClick="Button5_Click" Text="删 除" />
<asp:DropDownList ID="PageCountdrop" runat="server" AutoPostBack="True" OnSelectedIndexChanged="PageCountdrop_SelectedIndexChanged">
</asp:DropDownList></div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<meta http-equiv="Cache-Control"content="no-cache, must-revalidate"/>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">...
function ButtonSelect()
...{
var chkall= document.all["chkAll"];
if(chkall.checked==false)
...{
chkall.setAttribute("checked","true");
}
else
...{
chkall.checked = false;
}
AllSelect();
}
function AllSelect()
...{
var len=document.form1.elements.length;
var i;
var chkall= document.all["chkAll"];
if (chkall.checked == true)
...{
for (i=0;i<len;i++)
...{
if (document.form1.elements[i].type=="checkbox")
...{
document.form1.elements[i].checked=true;
}
}
}
else
...{
for (i=0;i<len;i++)
...{
if (document.form1.elements[i].type=="checkbox")
...{
document.form1.elements[i].checked=false;
}
}
}
}
var k = <%=num%>
function checkgou()
...{
var chkall= document.all["chkAll"];
var len=document.form1.elements.length;
var i;
var j=0;
for (i=0;i<len;i++)
...{
if (document.form1.elements[i].type=="checkbox")
...{
if (document.form1.elements[i].checked == true)
...{
j++;
}
}
}
if (j==k) ...{
chkall.checked = true;
}
//window.alert(len);
}
</script>
</head>
<body onload="checkgou()">
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Height="200px"
Width="700px" CaptionAlign="Left" AllowPaging="True" AllowSorting="True" OnSorting="GridView1_Sorting" HeaderStyle-Font-Underline="true" OnRowCreated="GridView1_RowCreated">
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<RowStyle BackColor="White" ForeColor="#003399" Font-Size="Small" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" Font-Size="Small" Height="20px" Font-Underline="True" HorizontalAlign="Center" VerticalAlign="Middle" />
<EditRowStyle Font-Size="Small" Height="20px" HorizontalAlign="Center" />
<AlternatingRowStyle Font-Size="Small" ForeColor="#00C000" HorizontalAlign="Center" />
<PagerSettings Visible="False" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input id="chkAll" onclick="AllSelect()" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CHK" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" BackColor="#E0E0E0" BorderStyle="Groove"
BorderWidth="1px" CommandArgument="first" ForeColor="Red" Text="首页" OnClick="PageChange_Click" />
<asp:Button ID="Button2" runat="server" BackColor="#E0E0E0" BorderStyle="Groove"
BorderWidth="1px" CommandArgument="prv" ForeColor="Red" Text="上一页" OnClick="PageChange_Click" />
<asp:Button ID="Button3" runat="server" BackColor="#E0E0E0" BorderStyle="Groove"
BorderWidth="1px" CommandArgument="next" ForeColor="Red" Text="下一页" OnClick="PageChange_Click" />
<asp:Button ID="Button4" runat="server" BackColor="#E0E0E0" BorderStyle="Groove"
BorderWidth="1px" CommandArgument="last" ForeColor="Red" Text="尾页" OnClick="PageChange_Click" />
<asp:Label ID="Label1" runat="server" Text="Label" Width="350px"></asp:Label>
<asp:TextBox ID="sorttext" runat="server" Visible="False"></asp:TextBox><br />
<input id="Button6" type="button" onclick="ButtonSelect()" value="全选" />
<asp:Button ID="Button5" runat="server" BackColor="#FFC0FF" BorderColor="#00C000"
BorderStyle="Solid" BorderWidth="1px" OnClick="Button5_Click" Text="删 除" />
<asp:DropDownList ID="PageCountdrop" runat="server" AutoPostBack="True" OnSelectedIndexChanged="PageCountdrop_SelectedIndexChanged">
</asp:DropDownList></div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
...{
public int num;
DataBase db = new DataBase();
protected void Page_Load(object sender, EventArgs e)
...{
if (!this.IsPostBack)
...{
Button5.Attributes.Add("onclick", "return confirm('确定要删除?')");
Session["strSqlpara"] = "";
GVBind();
}
num = GridView1.PageSize;
}
//GridView Binding
private void GVBind()
...{
string err="";
string sql = "SELECT MONITOR_ID as 设备号, MONITOR_SIM_ID as SIM卡号, TEMP_SELF as 导线温度, TEMP_CONNECTOR as 节点温度, E_CURRENT as 电流, RECEIVE_TIME as 采样时间, STATE as 状态 FROM CA_ALARM_RECORD ORDER BY RECEIVE_TIME";
DataTable dt = db.GetTableSource(sql,ref err);
//GridView1.AllowPaging = true;
// GridView1.PageSize = 10;
DataView dv = new DataView(dt);
dv.Sort = sorttext.Text;
GridView1.DataSource = dv;
GridView1.DataBind();
int page =GridView1.PageIndex+1;
int pagecount=GridView1.PageCount;
Label1.Text = "当前第"+page.ToString()+"页,总共 "+pagecount.ToString()+"页";
if (GridView1.PageIndex == 0)
...{
Button1.Enabled = false;
Button2.Enabled = false;
}
else
...{
Button1.Enabled = true;
Button2.Enabled = true;
}
if (GridView1.PageIndex == GridView1.PageCount - 1)
...{
Button3.Enabled = false;
Button4.Enabled = false;
}
else
...{
Button3.Enabled = true;
Button4.Enabled = true;
}
PageCountdrop.Items.Clear();
DropDownBind();
}
/**/////dropdown的绑定显示控制页面跳转
private void DropDownBind()
...{
for (int i = 1; i <= this.GridView1.PageCount; i++)
...{
this.PageCountdrop.Items.Add(i.ToString());
}
this.PageCountdrop.SelectedIndex = this.GridView1.PageIndex;
}
//分页函数
protected void PageChange_Click(object source , EventArgs e)
...{
/**//*保存checked*/
/**//********************************************************************************/
string strSqlpara;
strSqlpara = Convert.ToString(Session["strSqlpara"]);
for (int i = 0; i < GridView1.Rows.Count;i++ )
...{
CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CHK");
if (strSqlpara.IndexOf(GridView1.Rows[i].Cells[6].Text) != -1)
...{
if (chk.Checked == false)
...{
strSqlpara = strSqlpara.Replace("|'" + GridView1.Rows[i].Cells[6].Text + "'", "");
}
}
else
...{
if (chk.Checked == true)
...{
strSqlpara = strSqlpara + "|'" + GridView1.Rows[i].Cells[6].Text + "'";
}
}
}
Session["strSqlpara"] = strSqlpara;
/**//********************************************************************************/
string Arg = ((Button)source).CommandArgument.ToString();
switch(Arg)
...{
case "first":
GridView1.PageIndex = 0;
break;
case "prv":
GridView1.PageIndex = GridView1.PageIndex - 1;
break;
case "next":
GridView1.PageIndex = GridView1.PageIndex + 1;
break;
case "last":
GridView1.PageIndex = GridView1.PageCount - 1;
break;
default:
break;
}
GVBind();
/**//********************************************************************************/
/**//*换页后的循环判断*/
for (int p = 0; p < GridView1.Rows.Count;p++ )
...{
CheckBox chk = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[p].Cells[0].FindControl("CHK");
if (strSqlpara.IndexOf(GridView1.Rows[p].Cells[6].Text) != -1)
chk.Checked = true;
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
...{
string expre = e.SortExpression;
if (sorttext.Text.IndexOf("desc") == -1)
...{
sorttext.Text = e.SortExpression + " desc";
}
else
...{
sorttext.Text = e.SortExpression + " asc";
}
GVBind();
}
protected void Button5_Click(object sender, EventArgs e) //删除选中的
...{
bool kk=false;
for (int i = 0; i < GridView1.Rows.Count; i++)
...{
CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CHK");
if (chk.Checked == true)
...{
string err ="";
string id = GridView1.Rows[i].Cells[6].Text; //这里这个是日期,我是根据日期进行del
string sql = "delete from CA_ALARM_RECORD where RECEIVE_TIME=to_date('"+id+"','yyyy-mm-dd hh24:mi:ss')";
kk = db.ExceSql(sql, ref err);
}
}
GVBind();
if (kk)
...{
string sScript = "<Script>alert('删除成功!')</Script>";
Response.Write(sScript);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) //鼠标动作
...{
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
...{
if (e.Row.RowType == DataControlRowType.DataRow)
...{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#e6e6fa';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}
protected void PageCountdrop_SelectedIndexChanged(object sender, EventArgs e)
...{
GridView1.PageIndex = PageCountdrop.SelectedIndex;
GVBind();
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
...{
public int num;
DataBase db = new DataBase();
protected void Page_Load(object sender, EventArgs e)
...{
if (!this.IsPostBack)
...{
Button5.Attributes.Add("onclick", "return confirm('确定要删除?')");
Session["strSqlpara"] = "";
GVBind();
}
num = GridView1.PageSize;
}
//GridView Binding
private void GVBind()
...{
string err="";
string sql = "SELECT MONITOR_ID as 设备号, MONITOR_SIM_ID as SIM卡号, TEMP_SELF as 导线温度, TEMP_CONNECTOR as 节点温度, E_CURRENT as 电流, RECEIVE_TIME as 采样时间, STATE as 状态 FROM CA_ALARM_RECORD ORDER BY RECEIVE_TIME";
DataTable dt = db.GetTableSource(sql,ref err);
//GridView1.AllowPaging = true;
// GridView1.PageSize = 10;
DataView dv = new DataView(dt);
dv.Sort = sorttext.Text;
GridView1.DataSource = dv;
GridView1.DataBind();
int page =GridView1.PageIndex+1;
int pagecount=GridView1.PageCount;
Label1.Text = "当前第"+page.ToString()+"页,总共 "+pagecount.ToString()+"页";
if (GridView1.PageIndex == 0)
...{
Button1.Enabled = false;
Button2.Enabled = false;
}
else
...{
Button1.Enabled = true;
Button2.Enabled = true;
}
if (GridView1.PageIndex == GridView1.PageCount - 1)
...{
Button3.Enabled = false;
Button4.Enabled = false;
}
else
...{
Button3.Enabled = true;
Button4.Enabled = true;
}
PageCountdrop.Items.Clear();
DropDownBind();
}
/**/////dropdown的绑定显示控制页面跳转
private void DropDownBind()
...{
for (int i = 1; i <= this.GridView1.PageCount; i++)
...{
this.PageCountdrop.Items.Add(i.ToString());
}
this.PageCountdrop.SelectedIndex = this.GridView1.PageIndex;
}
//分页函数
protected void PageChange_Click(object source , EventArgs e)
...{
/**//*保存checked*/
/**//********************************************************************************/
string strSqlpara;
strSqlpara = Convert.ToString(Session["strSqlpara"]);
for (int i = 0; i < GridView1.Rows.Count;i++ )
...{
CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CHK");
if (strSqlpara.IndexOf(GridView1.Rows[i].Cells[6].Text) != -1)
...{
if (chk.Checked == false)
...{
strSqlpara = strSqlpara.Replace("|'" + GridView1.Rows[i].Cells[6].Text + "'", "");
}
}
else
...{
if (chk.Checked == true)
...{
strSqlpara = strSqlpara + "|'" + GridView1.Rows[i].Cells[6].Text + "'";
}
}
}
Session["strSqlpara"] = strSqlpara;
/**//********************************************************************************/
string Arg = ((Button)source).CommandArgument.ToString();
switch(Arg)
...{
case "first":
GridView1.PageIndex = 0;
break;
case "prv":
GridView1.PageIndex = GridView1.PageIndex - 1;
break;
case "next":
GridView1.PageIndex = GridView1.PageIndex + 1;
break;
case "last":
GridView1.PageIndex = GridView1.PageCount - 1;
break;
default:
break;
}
GVBind();
/**//********************************************************************************/
/**//*换页后的循环判断*/
for (int p = 0; p < GridView1.Rows.Count;p++ )
...{
CheckBox chk = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[p].Cells[0].FindControl("CHK");
if (strSqlpara.IndexOf(GridView1.Rows[p].Cells[6].Text) != -1)
chk.Checked = true;
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
...{
string expre = e.SortExpression;
if (sorttext.Text.IndexOf("desc") == -1)
...{
sorttext.Text = e.SortExpression + " desc";
}
else
...{
sorttext.Text = e.SortExpression + " asc";
}
GVBind();
}
protected void Button5_Click(object sender, EventArgs e) //删除选中的
...{
bool kk=false;
for (int i = 0; i < GridView1.Rows.Count; i++)
...{
CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CHK");
if (chk.Checked == true)
...{
string err ="";
string id = GridView1.Rows[i].Cells[6].Text; //这里这个是日期,我是根据日期进行del
string sql = "delete from CA_ALARM_RECORD where RECEIVE_TIME=to_date('"+id+"','yyyy-mm-dd hh24:mi:ss')";
kk = db.ExceSql(sql, ref err);
}
}
GVBind();
if (kk)
...{
string sScript = "<Script>alert('删除成功!')</Script>";
Response.Write(sScript);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) //鼠标动作
...{
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
...{
if (e.Row.RowType == DataControlRowType.DataRow)
...{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#e6e6fa';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}
protected void PageCountdrop_SelectedIndexChanged(object sender, EventArgs e)
...{
GridView1.PageIndex = PageCountdrop.SelectedIndex;
GVBind();
}
}
- asp.net2.0 GridView的整理使用
- asp.net2.0 GridView使用小记
- Asp.Net2.0新GridView控件使用
- Asp.Net2.0新GridView控件使用
- Asp.Net2.0新GridView控件使用
- asp.net2.0-GridView的操作
- asp.net2.0-GridView的操作
- asp.net2.0-GridView的操作
- asp.net2.0分页的实现(GridView)
- asp.net2.0-GridView的操作
- 【ASP.NET2.0】使用GridView绑定XmlDocument对象
- 关于使用ASP.NET2.0中GridView控件的一些技巧。
- 关于使用ASP.NET2.0中GridView控件的一些技巧。
- [学习笔记][ASP.NET2.0][Gridview][UpdateCommand的写法要点]
- ASP.NET2.0中GridView控件的介绍
- asp.net2.0中gridView的删除确认问题
- asp.net2.0操作GridView 的模板列
- ASP.NET2.0下含有DropDownList的GridView编辑、删除
- java中各种进制间的转换
- 从客户端中检测到有潜在危险的Request.Form值解决办法
- NHibernate 1.2 执行 视图(View)
- 转C++类型转换
- My first impression about TDD
- asp.net2.0 GridView的整理使用
- C#中获取IP MAC Name
- 要关心自己做了什么,而不是兴趣是什么
- 中国象棋.汉诺塔游戏.计算器.记事本.俄罗斯方块
- 标准模板库(STL)介绍
- 热烈庆祝十七大的召开
- MS SQL Server日期计算
- JSP连接SQL Server 2000系统配置
- NHibernate1.2 中 执行“存储过程”