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

推荐订阅源

J
Java Code Geeks
月光博客
月光博客
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
B
Blog
博客园_首页
G
Google Developers Blog
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
P
Proofpoint News Feed
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI

博客园 - 胡枫

ASP.NET URL Rewrite. URL重写 asp.net 中DataGrid自定义分页(简单,实用,易懂) 实现类似textarea这样可以滚动显示内容的方法 各种浏览器CSS hack方法 HTML+CSS+JS学习笔记 JS学习笔记ZT Asp.net 备份、还原Ms SQLServer及压缩Access数据库 我该怎样卸载IE7? ASP.NET Application,Session,Cookie和ViewState等对象用法和区别 (转) ASP读取显示TXT文件内容 ASP.NET 防注入的两个通用函数 innerText,outerText,innerHTML,outerHTML 如何在TextBox控件中显示系统当前时间?包括:年、月、日、时、分 ASP.NET 防注入的两个通用函数 C# 操作ACCESS数据库 ASP判断是否包含字符串(InStr 函数) asp.net2.0中Repeater的分页使用 ASP.NET2.0下含有DropDownList的GridView编辑、删除的完整例子! asp.net中没有类似asp中Left()函数怎么办?
一个GridView编辑删除的例子
胡枫 · 2007-11-21 · via 博客园 - 胡枫

<asp:GridView ID="myGvClass" runat="server" AutoGenerateColumns="False" Width="100%" DataKeyNames="id" OnRowCancelingEdit="myGvClass_RowCancelingEdit" OnRowEditing="myGvClass_RowEditing" OnRowUpdating="myGvClass_RowUpdating" OnRowDeleting="myGvClass_RowDeleting" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px">
              
<Columns>
                  
<asp:BoundField DataField="id" HeaderText="序号" ReadOnly="True">
                      
<ItemStyle HorizontalAlign="Center" />
                      
<HeaderStyle HorizontalAlign="Center" Width="10%" /></asp:BoundField>
                  
<asp:BoundField DataField="classname" HeaderText="栏目名称">
                      
<ItemStyle HorizontalAlign="Left" />
                      
<HeaderStyle HorizontalAlign="Left" Width="52%" />
                      
<ControlStyle Width="80%" />
                  
</asp:BoundField>
                  
<asp:BoundField DataField="stime" HeaderText="操作时间" ReadOnly="True">
                      
<ItemStyle HorizontalAlign="Center" />
                      
<HeaderStyle HorizontalAlign="Center" Width="20%" /></asp:BoundField>
                  
<asp:CommandField HeaderText="操作" ShowEditButton="True">
                      
<HeaderStyle HorizontalAlign="Center" Width="12%" />
                      
<ItemStyle HorizontalAlign="Center" /></asp:CommandField>
                  
<asp:TemplateField HeaderText="删除" ShowHeader="False">
                      
<ItemStyle HorizontalAlign="Center" />
                      
<HeaderStyle HorizontalAlign="Center" Width="6%" />
                      
<ItemTemplate>
                          
<asp:LinkButton ID="LinkButton1" OnClientClick="return confirm('您确认删除该记录吗?');" runat="server" CausesValidation="False" CommandName="Delete"
                              Text
="删除"></asp:LinkButton>
                      
</ItemTemplate>
                  
</asp:TemplateField>
              
</Columns>
              
<HeaderStyle BackColor="LightGray" />
              
</asp:GridView>

protected void myGvClass_RowEditing(object sender, GridViewEditEventArgs e)
    
{
        myGvClass.EditIndex 
= e.NewEditIndex;
        
this.myGvClass.EditRowStyle.BackColor = Color.AliceBlue;
        BinData();
    }

    
protected void myGvClass_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    
{
        myGvClass.EditIndex 
= -1;
        BinData();
    }

    
protected void myGvClass_RowUpdating(object sender, GridViewUpdateEventArgs e)
    
{
        
string strID = this.myGvClass.DataKeys[e.RowIndex].Value.ToString();
        
string strClassName = ((TextBox)(myGvClass.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim().ToString();

        WebClass.ArticleList tmp 
= new WebClass.ArticleList();
        tmp.EditClass(strClassName,strID);

        myGvClass.EditIndex 
= -1;
        BinData();
    }

    
protected void myGvClass_RowDeleting(object sender, GridViewDeleteEventArgs e)
    
{
        
string strID = this.myGvClass.DataKeys[e.RowIndex].Value.ToString();

        WebClass.ArticleList tmp 
= new WebClass.ArticleList();
        tmp.DelClass(strID);

        myGvClass.EditIndex 
= -1;
        BinData();
    }