惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
量子位
雷峰网
雷峰网
宝玉的分享
宝玉的分享
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
P
Privacy International News Feed
NISL@THU
NISL@THU
V
V2EX
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
IT之家
IT之家
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
大猫的无限游戏
大猫的无限游戏
V
Vulnerabilities – Threatpost
V
Visual Studio Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Hacker News
The Hacker News
Scott Helme
Scott Helme
H
Hacker News: Front Page
罗磊的独立博客
Hacker News - Newest:
Hacker News - Newest: "LLM"
K
Kaspersky official blog
S
Secure Thoughts
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Cloudflare Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
小众软件
小众软件
月光博客
月光博客
人人都是产品经理
人人都是产品经理
AI
AI
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Webroot Blog
Webroot Blog
博客园 - 【当耐特】
PCI Perspectives
PCI Perspectives
A
Arctic Wolf

博客园 - Blueeyes

挺有意思的小工具。。。 JS调用c#编写的DLL 笔记本CPU大全 搜集整理的一些SQL语句 .NET程序脱离.NET框架的方法 ASP.NET3.5的ListView与CSS Friendly ASP.NET页面中标题单点解决方案 微软一个罕为人知的无敌命令ntsd 微软一个罕为人知的无敌命令ntsd 全国主要城市的DNS服务器列表 静态构造器四个准则 .NET 中的对象序列化 .NET 中的数字格式化,日期格式化 别有用心的SQL 向水晶报表传递参数 在GridView的中有一个DropDownList,并且DropDownList有回传事件 纯CSS文字阴影效果实现 Excel轻松合并 写了一个查看SQL表结构的小工具
gridview的简单示例 (个人收藏)
Blueeyes · 2007-01-08 · via 博客园 - Blueeyes

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.OracleClient;
using System.Text;public partial class Default2 : System.Web.UI.Page
{
    
    
protected void Page_Load(object sender, EventArgs e)
    {
        
if (!Page.IsPostBack)
        {
           
            GetDataBak();
        }

    }

    更新

#region 更新
    
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        
//主键 .net2003 string strKey=DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
       string strKey = GridView1.DataKeys[e.RowIndex].Values[0].ToString();//更新的行  .net2003  string str=((TextBox)e.Item.Cells[1].Controls[0]).Text;
       string str = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;string strUpdate = string.Format("update xz_shoulidengji set baogaorenxm='{0}' where iidd='{1}'", str,strKey);string connectionstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

       OracleConnection conn 

= new OracleConnection(connectionstring);
       OracleCommand com 
= new OracleCommand(strUpdate, conn);
       conn.Open();
       com.ExecuteNonQuery();
       conn.Close();
this.GridView1.EditIndex = -1;
       GetDataBak();

   }

#endregion

   绑定数据

#region 绑定数据
   
private void GetDataBak()
    {
        
this.GridView1.DataSource = SqlDataSource1;
        
this.GridView1.DataBind();
    }
    
#endregion

    编辑

#region 编辑
    
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        
this.GridView1.EditIndex = e.NewEditIndex;
        GetDataBak();
    }
    
#endregion

    取消编辑

#region 取消编辑
    
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        
this.GridView1.EditIndex = -1;
        GetDataBak();

    }

#endregion

    翻页

#region 翻页
    
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        
this.GridView1.PageIndex = e.NewPageIndex;
        GetDataBak();

    }

#endregion

    删除

#region 删除
    
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        
string strKey = GridView1.DataKeys[e.RowIndex].Values[0].ToString();string strUpdate = string.Format("delete xz_shoulidengji  where iidd='{0}'", strKey);string connectionstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        OracleConnection conn 

= new OracleConnection(connectionstring);
        OracleCommand com 
= new OracleCommand(strUpdate, conn);
        conn.Open();
        com.ExecuteNonQuery();
        conn.Close();

        GetDataBak();

    }

#endregion

    排序

#region 排序
    
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        
//GridView1.SortDirection == SortDirection.Ascending;
        
//GridView1.SortExpression=SortDirection = SortDirection.Ascending;
        
    }
    
#endregion

    判断checkbox被选中

#region 判断checkbox被选中
    
protected void Button1_Click(object sender, EventArgs e)
    {
        StringBuilder SB 
= new StringBuilder();
        
for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            
// .net2003 if(((CheckBox)DataGrid1.Items[i].FindControl("CheckBox1")).Checked==true) string str=DataGrid1.Items[i].Cells[1].Text;
            CheckBox cb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            
if (cb.Checked)
            {
               
// 得到超连接的文本
                string hl = ((HyperLink)GridView1.Rows[i].Cells[1].Controls[0]).Text;
                SB.Append(hl);
// Response.Write(某某被选中);此处要用Text
                string strKey = GridView1.Rows[i].Cells[2].Text;
                SB.Append(strKey);
            }
        }

       
        Response.Write(

"<script>alert('"+SB.ToString()+"')</script>");

    }

#endregionprotected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            
//当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover""currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';");
            
//当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout""this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
        
//单击行改变行背景颜色 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add(
"onclick""this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
        }

    }
}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            AutoGenerateColumns
="False"  DataKeyNames="iidd" OnRowUpdating="GridView1_RowUpdating"  OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" OnSorting="GridView1_Sorting" OnRowDataBound="GridView1_RowDataBound">
            
<Columns>
                
<asp:TemplateField>
                    
<ItemTemplate>
                        
<asp:CheckBox ID="CheckBox1" runat="server" />
                    
</ItemTemplate>
                
</asp:TemplateField>
                
<asp:HyperLinkField DataNavigateUrlFields="anjianid" DataNavigateUrlFormatString="Default3.aspx?anjianid={0}"
                    DataTextField
="anjianid" HeaderText="ANJIANID"  />
                
<asp:BoundField DataField="BAOGAORENXM" HeaderText="BAOGAORENXM" SortExpression="BAOGAORENXM" />
                
<asp:BoundField DataField="IIDD" HeaderText="IIDD" SortExpression="IIDD" />
                
<asp:CommandField ShowEditButton="True" />
                
<asp:TemplateField ShowHeader="False">
                    
<ItemTemplate>
                        
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
                            Text
="删除" OnClientClick="return confirm('确定要删除此记录吗?')"></asp:LinkButton>
                    
</ItemTemplate>
                
</asp:TemplateField>
                
<asp:TemplateField>
                    
<ItemTemplate>
                        
<asp:HyperLink ID="HyperLink1" runat="server"></asp:HyperLink>
                    
</ItemTemplate>
                
</asp:TemplateField>
            
</Columns>
        
</asp:GridView>
        
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            ProviderName
="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT "ANJIANID", "BAOGAORENXM", "IIDD" FROM "XZ_SHOULIDENGJI"'>
        
</asp:SqlDataSource>
        
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    
    
</div>
    
</form>
</body>
</html>