资源简介
代码实现GridView的增删改查功能,适合于asp.net的初学者。

代码片段和文件信息
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string StrConnection = ConfigurationManager.ConnectionStrings[“testconnectionstring“].ConnectionString.ToString();
SqlConnection conn;
SqlCommand cmd;
protected void Page_Load(object sender EventArgs e)
{
if (!IsPostBack)
{
binddata();
}
}
protected void binddata()
{
conn = new SqlConnection(StrConnection);
conn.Open();
String sql = “select * from People“;
SqlDataAdapter myda = new SqlDataAdapter(sqlconn);
DataSet ds = new DataSet();
myda.Fill(ds “People“);
GridView1.DataSource = ds.Tables[“People“].DefaultView;
GridView1.DataBind();
conn.Close();
}
protected void GridView1_RowDeleting(object sender GridViewDeleteEventArgs e)
{
conn = new SqlConnection(StrConnection);
conn.Open();
String id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
int idt = int.Parse(id);
cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText= “delete from People where pkID = “ + idt;
cmd.ExecuteNonQuery();
conn.Close();
binddata();
}
protected void Button1_Click(object sender EventArgs e)
{
Response.Redirect(“add.aspx“);
}
protected void GridView1_RowUpdating(object sender GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
string pkid = GridView1.Rows[e.RowIndex].Cells[2].Text.ToString();
string name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim();
string sex = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.Trim();
string address = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text.Trim();
string born = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text.Trim();
string code = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text.Trim();
string SqlStr = “update People set pkID=‘“ + pkid + “‘Name=‘“ + name + “‘Sex=‘“ + sex + “‘Address=‘“ + address + “‘Born=‘“ + born + “‘Code=‘“ + code + “‘ where pkID=“ + pkid;
conn = new SqlConnection(StrConnection);
conn.Open();
cmd = new SqlCommand(SqlStr conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
GridView1.EditIndex = -1;
binddata();
}
protected void GridView1_RowEditing(object sender GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIn
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1000960 2007-09-25 12:52 test
文件 2585 2007-09-29 13:53 Default.aspx
文件 5051 2007-09-29 13:41 Default.aspx.cs
文件 492 2007-10-05 12:40 GridView.txt
- 上一篇:C#连接数据库表格显示
- 下一篇:c# 多线程轮询,等待,回调操作
相关资源
- C#简单三层架构,免去写增删改查
- c# + sqlite demo(增删改查)
- WPF+MVVM+DataGrid增删改查
- c# 开发与 mysql数据库实现的增删改查
- C# 用三层架构实现简单的增删改查
- 用ASP.NET初学者实现简单的增删改查功
- wpf信息管理系统 增删改查
- easy ui datagrid 增删改查+分页 asp.net
- c# 开发与mysql数据库实现的增删改查,
- c# 三层结构源码 增删改查
- asp.net MVC5 + Bootstrap 增删改查分页(最
- winform简单的增删改查
-
C# 3层架构操作xm
l文件(增删改查) - ASP.NET三层框架+MVC模式项目实现增删改
- asp.net mvc4 EF框架初学者增删改查源码
- ASP.NET MVC4 增删改查
- C# .net mvc 三层架构 增删改查
- WPF旅游管理系统增删改查实用
- C#宿舍管理系统-数据库增删改查
- asp.net Mvc 增删改查
- C# EF6连接、操作Mysql教程和增删改查
- ASP.NET三层架构样例代码2012版,含样例
- C#和ACCESS数据库的增删改查有注释三层
- ASP.NET 三层结构下使用GridView增删改查
- asp.net mvc linq to sql 增删改查 基本操作
- WPF校园成绩管理(实现增删改查)
-
winform对xm
l的增删改查 - c#连接sql,简易增删改查
- C#实现对Oracle数据库的增删改查
- C#实现增删改查 学生管理系统
评论
共有 条评论