Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have one button called "Submit".

When i click the button in gridview records is showing. but i want when i click the button i want to show progress bar "Loading please wait", then in the gridview records to be displayed.

How to do in c#?

What I have tried:

C#
protected void btnsubmit_Click(object sender, EventArgs e)
        {

         String strConnString = 
         ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                    SqlConnection con = new SqlConnection(strConnString);
               SqlCommand cmd = new SqlCommand("select * from tbl_trasnaction", con);
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter();
                    DataSet ds = new DataSet();
                    da.SelectCommand = cmd;
                    da.Fill(ds);
                    gridview.DataSource = ds;
                    gridiew.DataBind();
        }
Posted
Updated 30-Oct-18 5:16am
v2

You need to make use of so called multi-threading.
Take a look at this example :

Example. Please add a ProgressBar control to your Windows Forms program by double-clicking on the ProgressBar entry in the Toolbox. For this example, we also need a BackgroundWorker—add one and then create the event handlers required.

using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            // Start the BackgroundWorker.
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 1; i <= 100; i++)
            {
                // Wait 100 milliseconds.
                Thread.Sleep(100);
                // Report progress.
                backgroundWorker1.ReportProgress(i);
            }
        }

        private void backgroundWorker1_ProgressChanged(object sender,
            ProgressChangedEventArgs e)
        {
            // Change the value of the ProgressBar to the BackgroundWorker progress.
            progressBar1.Value = e.ProgressPercentage;
            // Set the text.
            this.Text = e.ProgressPercentage.ToString();
        }
    }
}
 
Share this answer
 
v2
Comments
Vincent Maverick Durano 30-Oct-18 12:17pm    
This will probably work for Windows forms. But I think the OP is on ASP.NET WebForms.
Leo Chapiro 30-Oct-18 16:52pm    
Why do you think so? OP asks "How to do in c#?"
Vincent Maverick Durano 30-Oct-18 18:11pm    
because GridView is an ASP.NET WebForms Server Control, not windows.
Leo Chapiro 31-Oct-18 5:48am    
You can use GridView in WPF: GridView In WPF
One approach is to use jQuery or Javascript to disable any / all elements within your page after your Button was clicked and display your image. Here's a quick example:

ASP.NET
<div id="divWait" style="position:absolute;left:50%; top:50%; margin:-100px 0 0 -150px; display:none;">
      <div style="text-align:center; width:300px; height:70px; background-color:#000; color:#fff;">
              Processing....
              <br/>
              <!--Your GIF image here-->
      </div>
</div>

<div id="divHolder">
      <!--Put your content here and Gridview-->
</div>
<asp:LinkButton ID="lnkSave" runat="server" CssClass="lnkSave" />

<script type="text/javascript">
    $(".lnkSave").live("click",function(){
        $("#divHolder").attr('disabled',true);
        $("#divWait").css({'display': 'block'});
    });
</script>


Another example would be using UpdatePanel + UpdateProgress control: Here's on example how to display progress bar when some actions is triggered from gridview: http://www.aspsnippets.com/Articles/Add-Edit-Update-Records-in-GridView-using-Modal-Popup-in-ASP.Net.aspx and here's an example on how to show progress bar indicator in all ajax operations: http://geekswithblogs.net/rashid/archive/2007/08/24/Showing-Modal-Progress-Dialog-in-all-Ajax-Operation.aspx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900