Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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


        }
like image 952
bluerain Avatar asked Dec 12 '22 14:12

bluerain


1 Answers

change the order:

 GridView1.DataBind();
 UpdatePanel1.Update();
like image 158
gbs Avatar answered Dec 22 '22 00:12

gbs