在gridview中页面刷新后删除链接按钮

时间:2013-04-04 10:48:27

标签: c# asp.net updatepanel

这是我使用链接按钮删除网格行的代码,但是在页面刷新后单击其删除的数据后我希望删除页面上的数据而不刷新页面我也将更新面板放在我的网格中这里是我的代码

protected void gvContent_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if(e.CommandName=="modify")
    {
        GridViewRow row = 
            (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

        // this find the index of row:
        int RowIndex = row.RowIndex; 

        //this store the  value in varName1:
        int id = Convert.ToInt32(
                   ((Label)row.FindControl("lblContentId")).Text.ToString()); 

        Response.Redirect("ContentManage.aspx?ContentId=" +Convert.ToInt32(id));
    }
    if (e.CommandName == "delete")
    {
        GridViewRow row = (GridViewRow)
                           (((LinkButton)e.CommandSource).NamingContainer);

        // this finds the index of row:
        int RowIndex = row.RowIndex; 

        //this stores the  value in varName1:
        int id = Convert.ToInt32(
                   ((Label)row.FindControl("lblContentId")).Text.ToString()); 

        Content_Data.DeleteContentDetails(id);
        BindGrid();
        UpdatePanel1.Update();
    }

2 个答案:

答案 0 :(得分:0)

您需要使用以下

将Content注册为异步回发控件
 void Page_Load()
    {
        if (!IsPostBack)
        {
            ScriptManager1.RegisterAsyncPostBackControl(gvContent);
        }

    }

这将导致您的网格进行异步回发。

希望有所帮助

答案 1 :(得分:0)

尝试添加空的RowDeleting事件

 protected void gvContent_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {

 }