代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (OleDbConnection olecon = new OleDbConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()))
{
string name = Session["name"].ToString(); {
try
{
olecon.Open();
OleDbCommand oledbcommand = new OleDbCommand("select * from StudentInfo where StudentId='" + name + "'", olecon);
OleDbDataReader da = oledbcommand.ExecuteReader();
this.GridView1.DataSource = da;
this.GridView1.DataKeyNames = new string[] { "StudentId" };
this.GridView1.DataBind();
da.Close();
}
catch (Exception)
{
throw;
}
}
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string A = GridView1.DataKeys[e.RowIndex].Value.ToString();
string B = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string C = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string D = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string E = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
string F = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string G = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();
string H = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.ToString().Trim(); string s = "update StudentId='" + A + "',StudentName='" + B + "',Sex='" + C + "',DateOfBirth='" + D + "',Specialty='" + E + "',Email='" + F + "',Root='" + G + ",PassWord='" + H + "'";
Response.Write("<script language=javascript> alert('数据更新成功!');window.location='ManagerNews.aspx'</script>");
}
}GridView
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (OleDbConnection olecon = new OleDbConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()))
{
string name = Session["name"].ToString(); {
try
{
olecon.Open();
OleDbCommand oledbcommand = new OleDbCommand("select * from StudentInfo where StudentId='" + name + "'", olecon);
OleDbDataReader da = oledbcommand.ExecuteReader();
this.GridView1.DataSource = da;
this.GridView1.DataKeyNames = new string[] { "StudentId" };
this.GridView1.DataBind();
da.Close();
}
catch (Exception)
{
throw;
}
}
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string A = GridView1.DataKeys[e.RowIndex].Value.ToString();
string B = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string C = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string D = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string E = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
string F = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string G = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();
string H = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.ToString().Trim(); string s = "update StudentId='" + A + "',StudentName='" + B + "',Sex='" + C + "',DateOfBirth='" + D + "',Specialty='" + E + "',Email='" + F + "',Root='" + G + ",PassWord='" + H + "'";
Response.Write("<script language=javascript> alert('数据更新成功!');window.location='ManagerNews.aspx'</script>");
}
}GridView
解决方案 »
- 用C#登录skydrive
- C#中double循环的问题
- 下载网页源码
- Infragistics UltraGrid 单元格背景图片
- 请解释这段代码,谢谢
- vs2005在《水晶报表》的几组表格中,插入一段空白段落【高分】
- 如何把一客户端的richtextbox中设定的字体和颜色发送到另一客户端的richtextbox中?
- 如何在同一 解决方案 同时又在不同项目中 实现 windows 窗体相互 调用,谢谢 !!
- [求助]c#,有啥办法,让做出来的软件不再需要别人安装.NET Framework么?
- lock的过程中出现异常后,别的程序还能进入到lock中来吗?
- C# TextBox
- 请教webBrowser.Navigate()网页跳转问题
另外 我很讨厌拼接字符串
下面这种写法 可以减少拼接出错
http://blog.csdn.net/shuyizhi/article/details/6100331