GridView .net访问
HTML code
- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting">
 - <Columns>
 - <asp:BoundField DataField="id" HeaderText="id" />
 - <asp:BoundField DataField="name" HeaderText="name" />
 - <asp:TemplateField ShowHeader="False">
 - <ItemTemplate>
 - <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
 - Text="删除" OnClientClick='<%# "if (!confirm(\"你确定要删除" + Eval("name").ToString() + "吗?\")) return false;"%>'></asp:LinkButton>
 - </ItemTemplate>
 - </asp:TemplateField>
 - </Columns>
 - </asp:GridView>
 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting"> <Columns> <asp:BoundField DataField="id" HeaderText="id" /> <asp:BoundField DataField="name" HeaderText="name" /> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="删除" OnClientClick='<%# "if (!confirm(\"你确定要删除" + Eval("name").ToString() + "吗?\")) return false;"%>'></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns></asp:GridView>
C# code
- private void BindGridView()
 - {
 - SqlConnection cn = new SqlConnection(@"server=.\SQLExpress;uid=sa;pwd=;database=Demo");
 - SqlDataAdapter da = new SqlDataAdapter("select id, name from yourtable", cn);
 - DataSet ds = new DataSet();
 - cn.Open();
 - da.Fill(ds);
 - cn.Close();
 - GridView1.DataSource = ds.Tables[0].DefaultView;
 - GridView1.DataKeyNames = new string[] { "id" };
 - GridView1.DataBind();
 - }
 - protected void Page_Load(object sender, EventArgs e)
 - {
 - if (!IsPostBack)
 - {
 - BindGridView();
 - }
 - }
 - protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 - {
 - string strSql = "delete from yourtable where id = @id";
 - SqlConnection cn = new SqlConnection(@"server=.\SQLExpress;uid=sa;pwd=;database=Demo");
 - SqlCommand cmd = new SqlCommand(strSql, cn);
 - cmd.Parameters.Add("@id", SqlDbType.VarChar, 11).Value = GridView1.DataKeys[e.RowIndex].Value.ToString();
 - cn.Open();
 - cmd.ExecuteNonQuery();
 - cn.Close();
 - BindGridView();
 - }
 
GridView .net访问的更多相关文章
- 扩展GridView控件——为内容项添加拖放及分组功能
		
引言 相信大家对GridView都不陌生,是非常有用的控件,用于平铺有序的显示多个内容项.打开任何WinRT应用或者是微软合作商的网站,都会在APP中发现GridView的使用.“Tiles”提供了一 ...
 - Access Grid Control Properties 访问网格控件属性
		
In this lesson, you will learn how to access the properties of a list form's Grid Control in WinForm ...
 - asp.net数据控件遍历 获取当前索引
		
Gridview 数据访问遍历1.for遍历for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//为gv的每一行增加js事件{ TextB ...
 - 在ASP.NET MVC5中实现具有服务器端过滤、排序和分页的GridView
		
背景 在前一篇文章<[初学者指南]在ASP.NET MVC 5中创建GridView>中,我们学习了如何在 ASP.NET MVC 中实现 GridView,类似于 ASP.NET web ...
 - GridView详细介绍
		
GridView控件的属性 表10.6 GridView控件的行为属性属性描述AllowPaging指示该控件是否支持分页.AllowSorting指示该控件是否支持排序.AutoGenerateCo ...
 - DevExpress.XtraGrid.view.gridview 属性说明
		
本文摘自: http://www.cnblogs.com/-ShiL/archive/2012/06/08/ShiL201206081335.html (一)双击展开,收缩字表 ExpandedChi ...
 - DevExpress GridView属性说明
		
转自http://www.cnblogs.com/-ShiL/archive/2012/06/08/ShiL201206081335.html (一)双击展开,收缩字表 1 Private Sub E ...
 - 关于Gridview的列名问题
		
Gridview的的数据绑定方法有两种: 一种就是datasourceid的绑定在绑定过程当中也可以通过select来选择性的绑定. 二种就是databind(): SqlDataAdapter da ...
 - 能分组的GridView
		
有天在想工作上的事的时候,看着.net原有的DataGridView,想起以前我写过的一篇文章,总结了一个好的Gird控件应该具备哪些功能,在那里我提及到了分组功能,就像jqGrid那样, 其实这样的 ...
 
随机推荐
- VSCode提示pylint isnot installed
			
1.下载所需扩展 在https://www.lfd.uci.edu/~gohlke/pythonlibs/中下载所需扩展,我下载的是:pylint-2.1.1-py2.py3-none-any.whl ...
 - Spring AOP的实现机制
			
AOP(Aspect Orient Programming),一般称为面向切面编程,作为面向对象的一种补充,用于处理系统中分布于各个模块的横切关注点,比如事务管理,日志,缓存等等.AOP 实现的关键在 ...
 - django中如何建立抽象型数据库作为父模块可继承其功能
			
先建立抽象数据库 from django.db import models class BaseModel(models.Model): """为模型类补充字段" ...
 - 基于Solr的多表join查询加速方法
			
前言 DT时代对平台或商家来说最有价值的就是数据了,在大数据时代数据呈现出数据量大,数据的维度多的特点,用户会使用多维度随意组合条件快速召回数据.数据处理业务场景需要实时性,需要能够快速精准的获得到需 ...
 - 关于 Linq to EF 的内存泄漏问题
			
查到一些解决方案: 1, http://www.codethinked.com/keep-your-iqueryable-in-check 自定义常用方法,屏蔽IQuery功能 ...
 - ajax(Asynchronous JavaScript and XML) 异步js或者xml
			
1.XMLHttpRequest 对象:向服务器发送局部的请求,异步获取执行 a.浏览器支持 b.语法: xmlhttp==new XMLHttpRequest(); xmlhttp.open(&qu ...
 - Ajax轮询 select循环输出
			
弹出层 <include file="Pub:header"/> <style> .del{color:red} .addname{color:#337ab ...
 - 在makefile通过宏定义来控制源程序的编译
			
在Makefile中我们可以通过宏定义来控制源程序的编译.只要在Makefile中的CFLAGS中通过选项-D来指定你于定义的宏即可. 如:CFLAGS += -D _XXX在编译的时候加上此选项就可 ...
 - python 3中 的subprocess
			
commands好像python3.6被去除了,它现在被subprocess替代了 FUNCTIONS getoutput(cmd) Return output (stdout or stderr) ...
 - Android TextUtils工具类的使用
			
1.采用File类,在指定目录下读写数据 java后台代码为: (1)向app的/data/data/com.example.lucky.helloworld目录下写入文本(涉及IO的读写操作) pa ...