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那样, 其实这样的 ...
随机推荐
- 「BZOJ 2342」「SHOI 2011」双倍回文「Manacher」
题意 记\(s_R\)为\(s\)翻转后的串,求一个串最长的形如\(ss_Rss_R\)的子串长度 题解 这有一个复杂度明显\(O(n)\)的做法,思路来自网上某篇博客 一个双倍回文串肯定当且仅当本身 ...
- nginx负载均衡tomcat和配置ssl
目录 tomcat 组件功能 engine host context connector service server valve logger realm UserDatabaseRealm 工作流 ...
- Python数组(二)
一.函数list 可将任何序列(如字符串)作为list的参数.list实际上是一个类,而不是函数. test=['java','C#','C','C++'] print(list(test)) ——& ...
- C++20草案中的宇宙飞船运算符(<=>,spaceship operator)
C++20草案中的宇宙飞船运算符(<=>,spaceship operator) Herb Sutter提议的新三路运算符<=>已经被合入C++20草案中. 宇宙飞船运算符(h ...
- js 有用信息集
1.java.cookie.js 库:轻易操作cookie 2.jquery.form.js 库:通过ajaxForm,ajaxsubmit 两个函数,将form转为ajax提交方式:https:// ...
- Python之freshman08 Socket
1. Socket介绍 概念 A network socket is an endpoint of a connection across a computer network. Today, mos ...
- php 利用 json 传递数组之中文乱码最新解决办法
json好用,但是如果数据中有中文就会出乱子了,网上解决办法多半是设置utf-8编码或转换字符编码 以下是我的解决办法,利用php的urlencode.urldecode函数(其实也是一种转换编码吧) ...
- day--41 mysql索引原理与慢查询优化
mysql索引原理与慢查询优化一:什么是索引 01:索引的出现是为了提高查询数据的效率 02:索引在mysql叫做“键” 或则“key“(primary key,uniquekey ,还有一个inde ...
- Party All the Time(三分)
In the Dark forest, there is a Fairy kingdom where all the spirits will go together and Celebrate th ...
- loj 2038 / 洛谷 P4345 [SHOI2015] 超能粒子炮・改 题解
好玩的推式子 题目描述 曾经发明了脑洞治疗仪与超能粒子炮的发明家 SHTSC 又公开了他的新发明:超能粒子炮・改--一种可以发射威力更加强大的粒子流的神秘装置. 超能粒子炮・改相比超能粒子炮,在威力上 ...