GridView中使用LinkButton添加启用禁用功能
菜鸟学习
前台
<asp:LinkButton ID="lkBtnStart" runat="server" CommandArgument='<%# Eval("es_status") +"&"+ Eval("es_No") %>' ForeColor="Red" Text='<%# Eval("es_status") %>' CommandName="UpStart">LinkButton</asp:LinkButton>
后台
protected void gvData_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
string o_No = e.CommandArgument.ToString();
UpdateCriteria uc = new UpdateCriteria(typeof(td_ExperienceShop));
uc.AddAttributeForUpdate(td_ExperienceShop.ES_STATUS, 0);//禁用此门店
Condition con = uc.GetNewCondition();
con.AddEqualTo(td_ExperienceShop.ES_NO, o_No);
if (uc.Perform() > 0)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('此删除为假删除,信息禁用成功!')", true);
this.GridViewBind();
return;
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('信息禁用失败!')", true);
return;
}
}
if (e.CommandName == "UpStart")
{
int j = 0;
string temp=e.CommandArgument.ToString();
string[] estr = temp.Split('&');
string start = estr[0];
string esNo = estr[1];
if (start == "0")
{
j = 1;
}
int k=ExperienceShopInfo.UpdateExperStatusByNo(j.ToString(),esNo);
if (k > 0)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('门店状态修改成功!')", true);
GridViewBind();
return;
}
////在此事件中转换类型为中文
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//LinkButton lbtnDelete = (LinkButton)e.Row.FindControl("ibtnDelete");
//lbtnDelete.Attributes.Add("onclick", "return confirm('确认要删除此门店信息吗?')");
LinkButton lbtn = (LinkButton)e.Row.Cells[9].FindControl("lkBtnStart");
if (lbtn.Text == "1")
{
lbtn.Text = "启用";
}
else
{
lbtn.Text = "禁用";
}
}