DataKeyNames="DB31_1,DB31_2" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_ RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSorting="GridView1_Sorting" >
<%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>
<%--
///
/// 绑定数据到GridView
///
vacío privado GridViewBind()
{
检索数据库
cadena strSql = "SELECCIONAR * DESDE DB1";
得到数据集
this.GridView1.DataSource=conn.GetDs(strSql).Tables[0].DefaultView;
this.GridView1.DataBind();
}
///
/// 编辑当前行
///
///
///
vacío protegido GridView1_RowEditing (remitente del objeto, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
//当前编辑行背景色高亮
this.GridView1.EditRowStyle.BackColor = Color.FromName("#F7CE90");
GridViewBind();
}
///
/// 取消编辑状态
///
///
///
vacío protegido GridView1_RowCancelingEdit (remitente del objeto, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
GridViewBind();
}
///
/// 删除记录过程
///
///
///
vacío protegido GridView1_RowDeleting (remitente del objeto, GridViewDeleteEventArgs e)
{
//得到单位编号
cadena filaToDelete = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
//转换为整数
//int ID=Convert.ToInt32(rowToDelete);
//从数据库中删除
cadena cadena = "ELIMINAR DE DB1 donde DB1_1=" + "'" + filaParaDelete + "'" + "";
intentar
{
conexión.RunSql(str);
//重新绑定数据
GridViewBind();
}
captura (Excepción ex)
{
Response.Write("数据库错误,错误原因:" + ex.Mensaje);
Respuesta.End();
}
}
///
/// 更新记录过程
///
///
///
vacío protegido GridView1_RowUpdating (remitente del objeto, GridViewUpdateEventArgs e)
{
ID de cadena = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
cadena DB1_1 = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Texto;
//cadena DB1_2 = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2")).Text;
cadena DB1_2 = (((DropDownList))GridView1.Rows[e.RowIndex].FindControl("ddlXL")).SelectedItem.Text;
//判断表单项是否有空并给出提示信息
si (DB1_1 == "" || DB1_2 == "")
{
conn.Alert("请输入完整信息!", Página);
devolver;
}
intentar
{
conn.BuilderEdit("seleccione * de DB1 donde DB1_1 ='" + ID + "'");
conexión.dr["DB1_1"] = DB1_1;
conexión.dr["DB1_2"] = DB1_2;
conexión.BuilderEditClose();
}
captura (error de OracleException)
{
si (err.Code.ToString() == "1")
conn.Alert("错误:已存在具有相同主键的记录", Página);
demás
conn.Alert("错误:未能添加记录", Página);
}
Response.Write("");
//返回浏览状态
GridView1.EditIndex = -1;
GridViewBind();
}
///
/// 分页事件
///
///
///
vacío protegido GridView1_PageIndexChanging (remitente del objeto, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridViewBind();
}
///
/// Lista desplegable de listas desplegables
///
///
///
vacío protegido GridView1_RowDataBound (remitente del objeto, GridViewRowEventArgs e)
{
//为DropDownList绑定值
if (((DropDownList)e.Row.FindControl("ddlXL")) != nulo)
{
DropDownList ddlXL = (DropDownList)e.Row.FindControl("ddlXL");
ddlXL.Items.Clear();
ddlXL.Items.Add(new ListItem("博士", "1"));
ddlXL.Items.Add(new ListItem("硕士", "2"));
ddlXL.Items.Add(new ListItem("学士", "3"));
}
//加入鼠标滑过的高亮效果
if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
{
//当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='amarillo',this.style.fontWeight='';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
}
//单击行改变行背景颜色
si (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
}
}