/// <summary>
/// 编辑选中事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
databinGrid();
}
/// <summary>
/// 编辑取消事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
databinGrid();
}
/// <summary>
/// 更新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
bbsjhwType.Id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
bbsjhwType.Name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
bbsjhwType.Update();
GridView1.EditIndex = -1;
databinGrid();
}
/// <summary>
/// 设置textbox宽度
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_PreRender(object sender, EventArgs e)
{
if (GridView1.EditIndex > -1)
{
TextBox TXTb = new TextBox();
for (int i = 1; i < 2; i++)
{
TXTb = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[i].Controls[0];
TXTb.Width = 50;
}
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
bbsjhwType.Id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
bbsjhwType.Delete(bbsjhwType.Id);
databinGrid();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[3].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?它相应的子类将也被删除')");
}
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
databinGrid();
}
/// 编辑选中事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
databinGrid();
}
/// <summary>
/// 编辑取消事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
databinGrid();
}
/// <summary>
/// 更新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
bbsjhwType.Id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
bbsjhwType.Name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
bbsjhwType.Update();
GridView1.EditIndex = -1;
databinGrid();
}
/// <summary>
/// 设置textbox宽度
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_PreRender(object sender, EventArgs e)
{
if (GridView1.EditIndex > -1)
{
TextBox TXTb = new TextBox();
for (int i = 1; i < 2; i++)
{
TXTb = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[i].Controls[0];
TXTb.Width = 50;
}
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
bbsjhwType.Id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
bbsjhwType.Delete(bbsjhwType.Id);
databinGrid();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[3].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?它相应的子类将也被删除')");
}
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
databinGrid();
}
供大家复制.