前台界面:

  <asp:GridView ID="GridView1" runat="server" Width="100%" CellPadding="" ForeColor="#333333"
AutoGenerateColumns="False" AllowPaging="True" PageSize="" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting"
DataKeyNames="id" OnPageIndexChanging="GridView1_PageIndexChanging"
GridLines="None" BorderStyle="Groove">
<Columns>
<asp:BoundField HeaderText="编号" DataField="id" Visible="false" />
<asp:BoundField HeaderText="序号" DataField="num" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="隧道名称" ReadOnly="True" />
<asp:BoundField DataField="tunnelClassName" HeaderText="隧道类别" ReadOnly="True" />
<asp:TemplateField HeaderText="起始点">
<ItemTemplate>
<%# Eval("PointStart")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tbStart" Text='<%# Eval("PointStart") %>' runat="server" Width="90px" />
</EditItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="长度">
<ItemTemplate>
<%# Eval("Length")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tbLength" Text='<%# Eval("Length") %>' runat="server" Width="90px" />
</EditItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" HeaderText="操作" />
</Columns>
<PagerSettings FirstPageText="" LastPageText="" NextPageText="" PreviousPageText="" />
<RowStyle Height="20px" BackColor="#FFF3EE" ForeColor="#333333" HorizontalAlign="Center"/>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#FE6D38" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#FE6D38" Font-Bold="True" ForeColor="Black"/>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>

后台代码:

 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridViewBind();
} protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -;
GridViewBind();
} protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Values[].ToString();
string connStr = ConfigurationManager.ConnectionStrings["NMXT_DBConn"].ConnectionString;
string SqlStr = "delete from TN_TunnelBlankPoints where id=" + id; try
{
SqlConnection conn = new SqlConnection(connStr);
if (conn.State.ToString() == "Closed") conn.Open();
SqlCommand comm = new SqlCommand(SqlStr, conn);
comm.ExecuteNonQuery();
comm.Dispose();
if (conn.State.ToString() == "Open") conn.Close(); GridView1.EditIndex = -;
GridViewBind();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
} protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridViewBind();
} protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Values[].ToString();
string strStart = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbStart")).Text;
string strLength = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbLength")).Text; string connStr = ConfigurationManager.ConnectionStrings["NMXT_DBConn"].ConnectionString;
string SqlStr = " update TN_TunnelBlankPoints set PointStart=" + strStart + ",Length=" + strLength + " where id=" + id; try
{
SqlConnection conn = new SqlConnection(connStr);
if (conn.State.ToString() == "Closed") conn.Open();
SqlCommand comm = new SqlCommand(SqlStr, conn);
comm.ExecuteNonQuery();
comm.Dispose();
if (conn.State.ToString() == "Open") conn.Close(); GridView1.EditIndex = -;
GridViewBind();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
}

GridView实现编辑删除的更多相关文章

  1. GridView总结二:GridView自带编辑删除更新

    GridView自带编辑删除更新逻辑很简单:操作完,重新绑定.总结总结,防止忘记... 效果图: 前台代码: <%@ Page Language="C#" AutoEvent ...

  2. GridView编辑删除操作

    第一种:使用DataSource数据源中自带的编辑删除方法,这样的不经常使用,在这里就不加说明了. 另外一种:使用GridView的三种事件:GridView1_RowEditing(编辑).Grid ...

  3. 利用yii2 gridview实现批量删除案例[转]

    今天仍然继续探讨GridView的问题,昨天有个小伙伴留言说你用gridview给我去掉表头的链接?我想啊想,这用gridview确实不容易实现,至少我没想出来,会的下方可留言.但是呢,这根gridv ...

  4. 利用yii2 gridview实现批量删除案例

    作者:白狼 出处:http://www.manks.top/article/yii2_gridview_deleteall本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置 ...

  5. editplus批量删除重复行(编辑-删除-删除重复行)

    editplus快速删除重复数据 多行文本,有些行的文字或数据是重复的,该怎么删除重复部分,只留下不重复的部分?很多人对这个问题感到无比头疼,Editplus同样能快速帮你删除数据. 那么,editp ...

  6. UITableView 自带编辑删除 自己定义button

    一:UITableView 自带编辑删除 1:实现两个方法就可以 #pragma mark   tableView自带的编辑功能 -(void)tableView:(UITableView *)tab ...

  7. GridView行编辑、更新、取消、删除事件使用方法

    注意:当启用编辑button时,点击编辑button后会使一整行都切换成文本框.为了是一行中的一部分是文本框,须要把以整行的全部列都转换成模板,然后删掉编辑模板中的代码.这样就能使你想编辑的列转换成文 ...

  8. 【ADO.NET基础-GridView】GridView的编辑、更新、取消、删除以及相关基础操作代码

    代码都是基础操作,后续功能还会更新,如有问题欢迎提出和提问....... 前台代码: <asp:GridView ID=" OnRowDataBound="GridView1 ...

  9. GridView编辑删除

    A前台代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.asp ...

随机推荐

  1. getopt函数的用法

    Linux提供了一个解析命令行参数的函数. #include <unistd.h> int getopt(int argc, char * const argv[], const char ...

  2. hdu1509(Windows Message Queue) 优先队列

    点击打开链接 Problem Description Message queue is the basic fundamental of windows system. For each proces ...

  3. 语言那点事,crt

    C语言标准(不管是ANSI 还是ISO)包含2部分,一部分是语言本身的标准,另一部分是C标准函数库.C标准函数库规定了函数的原型和功能,但是并没限定这些函数要怎么实现.所谓满足标准C规定的C编译器,不 ...

  4. hibernate 悲观锁乐观锁

    悲观锁和乐观锁是:在事务隔离机制中设置了ReadCommited的情况下,两种可以避免不可重复读的方式.   设置成读已提交是考虑到安全和处理速度,保证并发效率,但是在这个情况下仍然需要避免不可重复读 ...

  5. unsupported major.minor version 解决方法

        转载自http://hi.baidu.com/fatchong/blog/item/191da23b478bbfef15cecbae.html         一直以来都是用jdk1.5,这次 ...

  6. JDK自带监控工具 jps、jinfo、jstat、jmap、jconsole

    分类: JVM 2010-10-04 11:05 587人阅读 评论(0) 收藏 举报 工具jdkjava远程连接unixstring 常用有五个命令行工具: jinfo: 可以输出并修改运行时的ja ...

  7. python challenge - orc.py

    http://www.pythonchallenge.com/pc/def/ocr.html recognize the characters. maybe they are in the book, ...

  8. tcpdump抓包(转)

    Linux 环境下,通常通过 tcpdump 来进行抓包和分析.它是几乎所有 Linux 发行版本预装的数据包抓取和分析工具. tcpdump 工具的获取和安装可以参阅相应操作系统的官方文档,本文不再 ...

  9. vue 父子组件属性传递

    父子组件属性传递 注意:0.谁被引用,谁就算子组件  1.属性命名最好完全小写,否则需要如下格式转换:myAttr == my-attr 2.引入的vue组件后必须通过 components 注册才能 ...

  10. 28. Search a 2D Matrix 【easy】

    28. Search a 2D Matrix [easy] Write an efficient algorithm that searches for a value in an mx n matr ...