62,046
社区成员
发帖
与我相关
我的任务
分享
GridView1.DataKeyNames = new string[] { "ID" };//主键
GridView1.Rows[row.RowIndex].FindControl() as TextBox;
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id;
id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value);
DataSet ds1 = new DataSet();
string st1 = "delete from news where newid=" + id + "";
bool inser = db.UpdataBySql(st1);
if (inser == true)
{
//((LinkButton)e.RowIndex.Cells[10].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.RowIndex.Cells[2].Text + "\"吗?')");
}
bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox title;
TextBox kind;
TextBox href;
TextBox date;
TextBox time;
int id=Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
title = (TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0];
kind = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];
href=(TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0];
date = (TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0];
time = (TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0];
string ti = title.Text.Trim();
string ki = kind.Text.Trim();
string hr = href.Text.Trim();
string da = date.Text.Trim();
string tim=time.Text.Trim();
DataSet ds2 = new DataSet();
string str2 = "update news set title='"+ti+"',kind='"+ki+"',href='"+hr+"',dates='"+da+"',times='"+tim+"' where newid="+id+"";
bool inser = db.UpdataBySql(str2);
if (inser == true)
{
}
else { }
GridView1.EditIndex = -1;
bind();
}