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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recorded Future
Recorded Future
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
S
SegmentFault 最新的问题
博客园 - 司徒正美
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
MyScale Blog
MyScale Blog
腾讯CDC
博客园 - 聂微东
D
DataBreaches.Net
博客园 - Franky
人人都是产品经理
人人都是产品经理
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
量子位
宝玉的分享
宝玉的分享
D
Docker
T
Tailwind CSS Blog
IT之家
IT之家
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
Project Zero
Project Zero
Microsoft Azure Blog
Microsoft Azure Blog
AWS News Blog
AWS News Blog
Google DeepMind News
Google DeepMind News
H
Heimdal Security Blog
W
WeLiveSecurity
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
NISL@THU
NISL@THU
C
Cybersecurity and Infrastructure Security Agency CISA
Google DeepMind News
Google DeepMind News
T
Threatpost
TaoSecurity Blog
TaoSecurity Blog
N
News and Events Feed by Topic
aimingoo的专栏
aimingoo的专栏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
www.infosecurity-magazine.com
www.infosecurity-magazine.com
SecWiki News
SecWiki News
S
Securelist

博客园 - 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>