GridView里面的删除:
<asp:LinkButton ID="lbDelete" runat="server" OnClientClick="return confirm('你确定要删除吗?')" CommandName="del" CommandArgument='<%# Eval("fTypeId") %>'></asp:LinkButton>
#region 删除
/// <summary>
/// GridView1里面的删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "del")
{
BookInfo bi = new BookInfo();
bi.B_BarCode = e.CommandArgument.ToString();
BookInfoBLL.DelBookInfo(bi);
this.GridView1.DataBind();
}
}
#endregion
#region 光棒效果
/// <summary>
/// 光棒效果的方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover",
"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff';this.style.cursor='hand';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");
}
}
#endregion
#region 全选和反选
/// <summary>
/// 全选 和全不选
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox cb = (CheckBox)this.GridView1.Rows[i].FindControl("chbSelect");
if (this.CheckBox1.Checked == true)
{
cb.Checked = true;
}
else
{
cb.Checked = false;
}
}
this.CheckBox2.Checked = false;
}
/// <summary>
/// 反选
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox cb = (CheckBox)this.GridView1.Rows[i].FindControl("chbSelect");
if (cb == null)
continue;
if (cb.Checked == this.CheckBox2.Checked)
{
if (this.CheckBox2.Checked)
cb.Checked = false;
else
cb.Checked = true;
}
else
{
cb.Checked = this.CheckBox2.Checked;
}
}
}
#endregion
#region 批量删除
/// <summary>
/// 批量删除的方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDel_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox chkItem = this.GridView1.Rows[i].FindControl("chbSelect") as CheckBox;
if (chkItem != null && chkItem.Checked)
{
BookInfo model = new BookInfo();
model.B_BarCode = this.GridView1.DataKeys[i].Value.ToString();
BookInfoBLL.DelBookInfo(model);
}
}
this.GridView1.DataBind();
}
#endregion
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# string.Format("BookRecordInsert.aspx?B_BarCode={0}",Eval("B_BarCode")) %>'>修改</asp:HyperLink>
<asp:CommandField ShowEditButton="True" HeaderText="编辑" />