c# - UpdatePanel Gridview 不更新

标签 c# asp.net asp.net-ajax

出于某种原因,我无法在更新面板中让 Gridview 在我进行更改后进行刷新。有人可以帮忙吗?

我正在使用 ToolkitScriptManager 控件和 UpdatePanel。

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
   <ContentTemplate>
        <asp:GridView blah...

         </asp:GridView>

    </ContentTemplate>
   <Triggers>
       <asp:AsyncPostBackTrigger ControlID="DeleteButton" EventName="Click" />
       <asp:AsyncPostBackTrigger ControlID="IBUpUp" EventName="Click" />
       <asp:AsyncPostBackTrigger ControlID="IBDownDown" EventName="Click" />
       <asp:AsyncPostBackTrigger ControlID="IBUp" EventName="Click" />
       <asp:AsyncPostBackTrigger ControlID="IBDown" EventName="Click" />
       <asp:AsyncPostBackTrigger ControlID="EditProfile" EventName="Click" />
   </Triggers>

CS 页面

protected void Unnamed3_Click(object sender, ImageClickEventArgs e)
        {

            int rowIndex = GridView1.SelectedIndex;
            GridViewRow gvr = GridView1.SelectedRow;

            if (rowIndex >= 0)
            {
                //delete

                String GridViewOne = GridView1.DataKeys[rowIndex].Value.ToString();

                //delete image

                string imagename = gvr.Cells[2].Text;

                string pathToImage = @"C:\Images\";

                pathToImage = pathToImage + imagename;


                if (System.IO.File.Exists(pathToImage))
                {
                    // Use a try block to catch IOExceptions, to
                    // handle the case of the file already being
                    // opened by another process.
                    try
                    {
                        System.IO.File.Delete(pathToImage);
                    }
                    catch (System.IO.IOException m)
                    {
                        Console.WriteLine(m.Message);
                        return;
                    }
                }

                int bannerid = Convert.ToInt32(GridViewOne); 

                SqlDataReader sdr = null;

                SqlConnection conn = GetConnection();

                SqlCommand cmd = new SqlCommand("Tool_DeleteBannerAds", conn);

                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter param1 = new SqlParameter();

                param1.ParameterName = "@BannerID";
                param1.Value = bannerid;

                cmd.Parameters.Add(param1);

                conn.Open();

                sdr = cmd.ExecuteReader();

                sdr.Close();

                UpdatePanel1.Update();
                GridView1.DataBind();

            }
            else
            {
                //don't do anything
                //keep
                //Response.Redirect("Default.aspx");
            }


        }

最佳答案

改变顺序:

 GridView1.DataBind();
 UpdatePanel1.Update();

关于c# - UpdatePanel Gridview 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5476766/

相关文章:

c# - 为使用 ExcelPackage 创建的 Excel 单元格设置货币格式

C# protected read only auto property with only a get accessor vs protected readonly field

c# - 使用C#事件系统实现Publisher/Subscriber模式比用类接口(interface)实现有什么优势?

asp.net - 调试 ASP.Net 共享池技术

c# - 以编程方式创建 asp :Button and attach event in SharePoint

asp.net - 我如何从Ajax调用Web API Controller

c# - 使用 UpdateProgress 的问题

c# - 将日志发送到 Unity 应用程序中的标准输出

jquery - ASP.NET - Bootstrap 下拉导航仅在根页面上工作

c# - Image.FromStream(PostedFile.InputStream) 失败。 (参数无效。)(AsyncFileUpload))