【问题标题】:Delete link button work after page refresh in gridview在gridview中刷新页面后删除链​​接按钮工作
【发布时间】:2013-04-04 10:48:27
【问题描述】:

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

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();
    }

【问题讨论】:

    标签: c# asp.net updatepanel


    【解决方案1】:

    您需要使用以下方法将 gvContent 注册为异步回发控件

     void Page_Load()
        {
            if (!IsPostBack)
            {
                ScriptManager1.RegisterAsyncPostBackControl(gvContent);
            }
    
        }
    

    这将导致您的 Grid 执行异步回发。

    希望有帮助

    【讨论】:

      【解决方案2】:

      尝试添加一个空的 RowDeleting 事件

       protected void gvContent_RowDeleting(object sender, GridViewDeleteEventArgs e)
       {
      
       }
      

      【讨论】:

        猜你喜欢
        • 2020-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-08
        • 1970-01-01
        • 1970-01-01
        • 2015-01-14
        • 1970-01-01
        相关资源
        最近更新 更多