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那样, 其实这样的 ...
随机推荐
- dota有哪些经典的典故或笑话?
----------------------------------------------------dota有哪些经典的典故或笑话?虽然现在玩游戏也没什么热情了, 但是看到这些还是笑尿,笑点低 = ...
- 基于Solr的多表join查询加速方法
前言 DT时代对平台或商家来说最有价值的就是数据了,在大数据时代数据呈现出数据量大,数据的维度多的特点,用户会使用多维度随意组合条件快速召回数据.数据处理业务场景需要实时性,需要能够快速精准的获得到需 ...
- MongoSQL 复制数据表报错
报错内容为: [thread1] SyntaxError: identifier starts immediately after numeric literal @(shell):1:2 解决方案: ...
- Pycharm关闭后Python.exe还是在后台运行
pycharm运行程序关闭后会弹出一个对话框: 一定要选择第一个,不然python.exe一直会在后台运行.
- c语言数据结构学习心得——栈
栈(Stack) 只允许在一端进行插入或删除操作的线性表 栈顶(Top):栈中允许进行插入和删除操作的那一端: 栈底(Bottom):固定的,不允许进行插入或删除的另一端 1.栈是受限的线性表,所以自 ...
- [POI2007]ZAP-Queries 数学
题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...
- 24.Letter Combinations of a Phone Number(电话号对应的字符组合)
Level: Medium 题目描述: Given a string containing digits from 2-9 inclusive, return all possible lette ...
- Flask Web开发实战(入门、进阶与原理解析)
URL重定向 错误响应 > 如果你想手动返回错误响应,可以使用Flask提供的abort()函数. XML 上下文全局变量 [](https://img2018.cnblogs.com/blog ...
- 基于中间件的RBAC权限控制
RBAC 是什么 RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联. 在 Django 中,权限就是用户对一个包含正则表达式 url ...
- POJ 2182 Lost Cows (求序列第k大)
题解 二分+树状数组 显然最和一个数的值就是rank 那么其它数有什么规律? 从后往前匹配rank,我们可以发现第i个数的rank为还没有匹配的rank第(a[i]+1)大的数 这可以用 树状数组+二 ...