1、查询
SqlDataSource1.FilterExpression = "name like '%" + TextBox1.Text.Trim() + "%'";
重点:FilterExpression 添加查询条件
2、删除
1)Page_Load事件中为删除按钮添加提示
ButtonDelete.Attributes.Add("onclick", "return confirm('确定要删除所选行吗?');");
2)删除按钮单击事件部分代码:
bool selected = false;
string indexs = "";
for (int i = 0; i < GridViewUserList.Rows.Count; i++)
{
CheckBox ckb = (CheckBox)(GridViewUserList.Rows[i].FindControl("CheckBoxSelect"));
if (ckb.Checked)
{
selected = true;
indexs += Convert.ToString(GridViewUserList.DataKeys[i].Value) + ",";
}
}
if (selected)
{
string[] index = indexs.Trim(',').Split(',');
for (int i = 0; i < index.Length; i++)
{
if (index[i] == "") continue;
try
{
bookuser.Delete(index[i].ToString ());
}
catch (Exception err)
{
Page.Controls.Add(Common.showMsg(err.Message));
break;
}
}
Page.Controls.Add(Common.showMsg("删除成功!"));
GridViewUserList.DataBind();
}
else
{
Page.Controls.Add(Common.showMsg("请先选择要删除的行!"));
}
有更加好的方法,请各位亲们回帖分享奥! |