title: gridview RowUpdating event using asp:Command Field type button
body: <p>I am using asp command field type button for editing gridview row. 
  A row is suppose to be not showing in the grid whenever user update a record. The ShowAllClasses() method is suppose to fetch records from sql db excluding recently updated row. </p>
  
  <p>Now behavior of "Update" Command Field Button.</p>
  
  <p><strong>Localhost</strong>:
  As I click on the button it hides the row (means binding is done again). In this case record gets updated once. (as required) </p>
  
  <p><strong>On deployed application</strong>:
  Upon user click the row doesn't hide and user is able to click many times on the button (as if function is not working). But as user stops clicking button, after a minor delay, editing mode of gridview goes away and binding after update is fired.</p>
  
  <p>Bad thing is that the sql table updates each time button is clicked. 
  Help me how I can fix this.</p>
  
  <p>Here is code I am using </p>
  
  <p><strong>Markup of command field inside GridView1</strong>:</p>
  
  <pre><code>&lt;asp:CommandField ButtonType="Button" HeaderText="Edit/Update" ShowEditButton="True"
                              ShowHeader="True" UpdateText="Set Class" ItemStyle-HorizontalAlign="Center" /&gt;
  </code></pre>
  
  <p><strong>GridView RowUpdating Event</strong>:</p>
  
  <pre><code>protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
  
          lblError.Text = string.Empty;
  
          int iTutorID = Convert.ToInt32(Session["EID"]);
  
          DropDownList ddlTime = GridView1.Rows[e.RowIndex].FindControl("ddlClassTime") as DropDownList;
          string sClassTime = ddlTime.SelectedItem.Text;
  
          HiddenField hf = GridView1.Rows[e.RowIndex].FindControl("sIdHidden") as HiddenField;
          int iSID = Convert.ToInt32(hf.Value);
  
          hf = GridView1.Rows[e.RowIndex].FindControl("cIdHidden") as HiddenField;
          int iCID = Convert.ToInt32(hf.Value);
  
          hf = GridView1.Rows[e.RowIndex].FindControl("hfClassTime") as HiddenField;
          string sOriginalClassTime = hf.Value.ToString();
  
          if (sOriginalClassTime.Length &lt; 8)
              sOriginalClassTime = "0" + sOriginalClassTime;
  
          DropDownList ddlDate = GridView1.Rows[e.RowIndex].FindControl("ddlClassDate") as DropDownList;
          DateTime dNewDate = Convert.ToDateTime(ddlDate.SelectedValue);
  
          Label lblLesson = GridView1.Rows[e.RowIndex].FindControl("lblLesson") as Label;
          string sLesson = lblLesson.Text;
  
          DateTime dClassDate = Convert.ToDateTime(ddlAdvDay.SelectedValue);
  
          //cond: same date and same time set
          if (sOriginalClassTime == sClassTime &amp;&amp; dNewDate == dClassDate.Date)
          {
              //show error
              lblError.Text = "Same class date and time cannot be set as Advanced class";
              return;
          }
  
          lblError.Text = string.Empty;
  
          BLClass blClass = new BLClass();
          //1. insert in makeup table today's class
          //2. insert in classdetails table
  
          //1. insert in makeup table with today's date
          blClass.InsertAdvancedClass(iTutorID, iSID, iCID, dClassDate, dNewDate);
  
          //2. insert in classdetails table
          blClass.InsertClassDetails(iTutorID, iSID, iCID, dNewDate, sClassTime, "Advanced", sLesson);           
  
  
          GridView1.EditIndex = -1;
          ShowAllClasses();
  }
  </code></pre>
  
  <p><strong>Method for Binding Grid with DataSource</strong>:</p>
  
  <pre><code>private void ShowAllClasses()
  {
          lblError.Text = string.Empty;
  
          int iTutorID = Convert.ToInt32(Session["EID"]);    
  
          BLClass blClass = new BLClass();
  
          DateTime dClassDate = Convert.ToDateTime(ddlAdvDay.SelectedValue);
  
  
          DataTable dtClass = blClass.GetAdvancedClasses(iTutorID, dClassDate.Date);            
  
          //temp method for date display format
          FixDateFormat(dtClass);
          dtClass.AcceptChanges();
  
          GridView1.DataSource = dtClass;
          GridView1.DataBind();
   }
  </code></pre>