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那样, 其实这样的 ...
随机推荐
- C# Winform下一个热插拔的MIS/MRP/ERP框架11(启航)
初学时,有了想法却完全不知道该从何下指,此序列将抛砖引玉,与大家共同学习进步. 一个程序的初始,必然是启动. 我的要求: 1.应用程序保持单例: 2.从配置文件加载一些基础数据进行初始化: 3.显示软 ...
- mysql主从服务器
#mysql主从服务器 mysql-bin.003673 | 106 查看错误日志show variables like '%log_error%'; replicate-do-table=testm ...
- redis集群如何解决重启不了的问题
redis使用集群部署,如果遇到断电或者服务器重启,当再次启动的时候,有时候会启动不了.需要使用trib的fix命令进行修复.如果修复还是不行的话,可以清除节点数据再重新建集群,前提要备份之后操作. ...
- Python里生成器的问题
任何包含yield语句的函数称为生成器.
- pip_install的安装
1.下载get-pip.py https://pip.pypa.io/en/latest/installing/#id9 2.运行 python get-pip.py 3.python -m pip ...
- CodeCraft-19 and Codeforces Round #537 (Div. 2) C. Creative Snap 分治
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their bas ...
- ssh 远程登录TX2
TX2 端SSH操作 安装: sudo apt-get install openssh-server 确认sshserver是否启动: ps -e |grep ssh 如果看到sshd那说明ssh-s ...
- 用IDM下载博客图片
前言 写博客的人一定都会有一个图床,将图片存在那里.发现自己以前没有注意图片来源问题,随手就贴在博客上面了.现在有不少图片都挂了,换句话来说有可能自己目前用的图床不提供服务了,那所有的图片都有可能丢失 ...
- Python闭包需要注意的问题
定义 python中的闭包从表现形式上定义为:如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure),也就是说内层函数引用了外层函数 ...
- CMM模型,结构化开发方法和面向对象开发方法的比较,UML(统一建模语言),jackson开发方法
CMM模型 一.CMM简介 CMM,英文全称为Capability Maturity Model for Software,即:软件成熟度模型. CMM的核心是把软件开发视为一个过程.它是对于软件在定 ...