Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

c# - UpdatePanel Gridview not updating

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>

Cs Page

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


        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

change the order:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...