GridView的UpdatePanel的不更新

GridView的UpdatePanel的不更新

本文介绍了GridView的UpdatePanel的不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,我不能在UpdatePanel的GridView的我做了更改后刷新。有人可以帮忙吗?

我使用的ToolkitScriptManager控制在UpdatePanel。

 < ASP:的UpdatePanel ID =UpdatePanel1=服务器的UpdateMode =条件>
   <&的ContentTemplate GT;
        < ASP:GridView控件等等...         < / ASP:GridView的>    < /&的ContentTemplate GT;
   <&触发器GT;
       < ASP:AsyncPostBackTrigger控件ID =DeleteButton事件名称=点击/>
       < ASP:AsyncPostBackTrigger控件ID =IBUpUp事件名称=点击/>
       < ASP:AsyncPostBackTrigger控件ID =IBDownDown事件名称=点击/>
       < ASP:AsyncPostBackTrigger控件ID =IBUp事件名称=点击/>
       < ASP:AsyncPostBackTrigger控件ID =IBDown事件名称=点击/>
       < ASP:AsyncPostBackTrigger控件ID =EditProfile事件名称=点击/>
   < /触发器>

保护无效Unnamed3_Click(对象发件人,ImageClickEventArgs E)
        {

  INT的rowIndex = GridView1.SelectedIndex;
        GridViewRow GVR = GridView1.SelectedRow;        如果(rowIndex位置> = 0)
        {
            //删除            字符串GridViewOne = GridView1.DataKeys [rowIndex位置] .Value.ToString();            //删除图像            串imagename = gvr.Cells [2]。文本;            字符串映像路径= @C:\\图片\\;            映像路径=映像路径+ imagename;
            如果(System.IO.File.Exists(映像路径))
            {
                //使用try块捕获的IOExceptions,以
                //处理文件的情况下,已被
                //被另一个进程打开。
                尝试
                {
                    System.IO.File.Delete(映像路径);
                }
                赶上(System.IO.IOException米)
                {
                    Console.WriteLine(m.Message);
                    返回;
                }
            }            INT bannerid = Convert.ToInt32(GridViewOne);            SqlDataReader的特别提款权= NULL;            康涅狄格州的SqlConnection =的getConnection();            CMD的SqlCommand =新的SqlCommand(Tool_DeleteBannerAds,康恩);            cmd.CommandType = CommandType.StoredProcedure;            SqlParameter的参数1 =新的SqlParameter();            param1.ParameterName =@BannerID;
            param1.Value = bannerid;            cmd.Parameters.Add(参数1);            conn.Open();            SDR = cmd.ExecuteReader();            sdr.Close();            UpdatePanel1.Update();
            GridView1.DataBind();        }
        其他
        {
            //什么都不做
            //保持
            //Response.Redirect(\"Default.aspx);
        }
    }


解决方案

更改顺序:

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

For some reason, I can't get the Gridview in the Updatepanel to refresh after I've made changes. can someone help?

I'm using the ToolkitScriptManager control and the 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>

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


    }
解决方案

change the order:

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

这篇关于GridView的UpdatePanel的不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 19:51