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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - Blueeyes

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