请教两个代码的意思~ 跪求了!!!!!!!!!!!!!!!

kof821117 2009-04-16 06:52:13
想请教每一个详细意思,谢谢了!!!

第一个:
 protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}

//del
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "";
sqlstr = "delete from [Booking] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
sqlstr = "delete from [Grug Allergy] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
sqlstr = "delete from [Patient_History] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
sqlstr = "delete from [Waiting List] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
sqlstr = "delete from [Patients] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
bind();
}

//update
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sqlstr = "update Patients set P_Name='"
// + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',ID_Card='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',Guardian_Name='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "' where PatientID='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
GridView1.EditIndex = -1;
bind();
}

//
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}





第二个~~:


public void bind(string sqlorder)
{
string sqlstr="";
string sqlwhere = "";
if ((this.DropDownList1.SelectedValue.Length > 0) && (this.TextBox1.Text.Length > 0))
{
sqlstr = "select * from Patients where [" + this.DropDownList1.SelectedValue + "] like '%%%%" + this.TextBox1.Text + "%%%%%'";
}
else
{
sqlstr = "select * from Patients ";
}

if (sqlwhere != "")
{
sqlstr = sqlstr + sqlwhere;
}
if (sqlorder != "")
{
sqlstr = sqlstr + sqlorder;
}

GridView1.DataSource = sqlHp.SQLDataset(sqlstr);
GridView1.DataKeyNames = new string[] { "PatientID" };//pk key
GridView1.DataBind();
}

...全文
398 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
星小野 2011-08-30
  • 打赏
  • 举报
回复
还是女孩子心细有这样的魄力!!!
看到这样的代码,不死也的残,你坚强的还做了注释.我...走了...
[Quote=引用 2 楼 itliyi 的回复:]
先去看看gridview的基本 运用

窗体加载调用bind()方法显示数据
if (!IsPostBack)
{
bind();
}
public void bind(string sqlorder)
{
string sqlstr="";
string sqlwhere = "";
if ((this.DropDownList1.Select……
[/Quote]
szldk 2009-04-17
  • 打赏
  • 举报
回复
mark
amwsse21q 2009-04-16
  • 打赏
  • 举报
回复
呵呵
woodt 2009-04-16
  • 打赏
  • 举报
回复
现在的黄金不值钱啦?
Zeteyu 2009-04-16
  • 打赏
  • 举报
回复
1
GridView1_RowEditing //按GridView“编辑”按钮后发生的事件
GridView1_RowDeleting //按“删除”按钮后发生的事件
GridView1_RowUpdating //编辑确认时发生的事件
GridView1_RowCancelingEdit //取消编辑时发生的事件

2
bind //按照DropDownList所选的值进行数据绑定
walkghost 2009-04-16
  • 打赏
  • 举报
回复
我汗。。。
lukeye 2009-04-16
  • 打赏
  • 举报
回复

while(不会)
{
//理解中ing。。。
}
djwdsj 2009-04-16
  • 打赏
  • 举报
回复
我也期待解释!
zhoulehua 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 itliyi 的回复:]
先去看看gridview的基本 运用

窗体加载调用bind()方法显示数据
if (!IsPostBack)
{
bind();
}
public void bind(string sqlorder)
{
string sqlstr="";
string sqlwhere = "";
if ((this.DropDownList1.SelectedValue.Length > 0) && (this.TextBox1.Text.Length > 0)) //如果下拉列表选中了值并且文本框有文本
{
sqlstr = "select *…
[/Quote]

赞一个
lyl222 2009-04-16
  • 打赏
  • 举报
回复
帮顶,接分~
cnwolfs 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kkun_3yue3 的回复:]
叹为观止
[/Quote]

支持
itcrazyman 2009-04-16
  • 打赏
  • 举报
回复
帮顶,楼上正解
itliyi 2009-04-16
  • 打赏
  • 举报
回复
先去看看gridview的基本 运用

窗体加载调用bind()方法显示数据
if (!IsPostBack)
{
bind();
}
public void bind(string sqlorder)
{
string sqlstr="";
string sqlwhere = "";
if ((this.DropDownList1.SelectedValue.Length > 0) && (this.TextBox1.Text.Length > 0)) //如果下拉列表选中了值并且文本框有文本
{
sqlstr = "select * from Patients where [" + this.DropDownList1.SelectedValue + "] like '%%%%" + this.TextBox1.Text + "%%%%%'"; 根据选择条件查询
}
else
{
sqlstr = "select * from Patients "; //没有就查询所有记录
}

if (sqlwhere != "")
{
sqlstr = sqlstr + sqlwhere;
}
if (sqlorder != "")
{
sqlstr = sqlstr + sqlorder;
}

GridView1.DataSource = sqlHp.SQLDataset(sqlstr); //调用方法把返回的datatable赋值给grdiview
GridView1.DataKeyNames = new string[] { "PatientID" };//pk key //主键 一般用于修改删除
GridView1.DataBind();
}


protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex; //编辑
bind();
}


protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}//取消编辑


protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{//去除主键条件删除
string sqlstr = "";
sqlstr = "delete from [Booking] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
sqlstr = "delete from [Grug Allergy] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
sqlstr = "delete from [Patient_History] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
sqlstr = "delete from [Waiting List] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);
sqlstr = "delete from [Patients] where PatientID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);//执行删除方法
bind();//重新绑定控件
}



protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{//取出主键修改操作
//基本的sql语句
string sqlstr = "update Patients set P_Name='"
// + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',ID_Card='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',Guardian_Name='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "' where PatientID='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlHp.SQLExecute(sqlstr);//执行
GridView1.EditIndex = -1;//变为不可编辑状态
bind();//重新绑定
}

kkun_3yue3 2009-04-16
  • 打赏
  • 举报
回复
叹为观止
jdhlowforever 2009-04-16
  • 打赏
  • 举报
回复
up
esft 2009-04-16
  • 打赏
  • 举报
回复
up
yanlongwuhui 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kkun_3yue3 的回复:]
叹为观止
[/Quote]
同意
wuyq11 2009-04-16
  • 打赏
  • 举报
回复
1 绑定数据,修改,通过主键删除数据
2 通过条件构造SQL语句,查询再绑定

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧