title: GridView Disappears on Update Button Click, Doesn't Update Record
body: <p>So I have a c# page with a GridView. For some reason, after adding the label and the template for editing, when I click the update button in the edit column, the GridView disappears and none of the records get changed. I know I need to databind the values in the edit box once the user clicks update but I'm not sure how. Can anyone give any suggestions?</p>
  
  <p>Here is my code.</p>
  
  <pre><code>public partial class CMSWebParts_Custom_Development_DevWebPart : 
  CMSAbstractWebPart
  {
  
  public string paramId;
  
  protected void Page_Load(object sender, EventArgs e)
  {
      if (!IsPostBack)
      {
          ViewState["RefUrl"] = Request.UrlReferrer.ToString();
      }
      string urlString = Request.UrlReferrer.ToString();
      paramId = HttpUtility.ParseQueryString(urlString).Get("Theid");
  
      DispatchNumberLabel.Text = getDispatchNumber();
      //TerminalLabel.Text = getTerminal();
      DispatchInfoIdLabel.Text = getDispatchInfoId();
      DriverNameLabel.Text = getDriverName();
  }
  
  protected string getDispatchInfoId()
  {
      string result = DriverDropDownList.SelectedValue;
      return result;
  }
  
  protected string getDispatchNumber()
  {
      string result = paramId;
      return result;
  }
  
  protected string getTerminal()
  {
      string result;
      string connectionString = "";
      using (var con = new SqlConnection(connectionString))
      {
          var sql = "Select Terminal from Form_IntranetSharpTransit_DispatchInfo where ([Dispatch] = @Dispatch)";         
          using (var cmd = new SqlCommand(sql, con))
          {
              cmd.Parameters.AddWithValue("@Dispatch", getDispatchNumber());
              con.Open();
              result = (string)cmd.ExecuteScalar();
          }
      }
      return result;
  }
  
  protected string getDriverName()
  {
      string result;
      string connectionString = "";
      using (var con = new SqlConnection(connectionString))
      {
          var sql = "Select Driver from Form_IntranetSharpTransit_DispatchInfo WHERE ([DispatchInfoID] = @DispatchInfoId)";
          using (var cmd = new SqlCommand(sql, con))
          {
              cmd.Parameters.AddWithValue("@DispatchInfoId", getDispatchInfoId());
              con.Open();
              result = (string)cmd.ExecuteScalar();
          }
      }
      return result;
  } 
  }
  </code></pre>
  
  <p>And here is my code behind. </p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" 
  CodeFile="~/CMSWebParts/Custom/Development/DevWebPart.ascx.cs" 
  Inherits="CMSWebParts_Custom_Development_DevWebPart" %&gt;
  &lt;%--&lt;script runat="server"&gt;
  
  protected void Page_Load(object sender, EventArgs e)
  {
  
  }
  &lt;/script&gt;--%&gt;Dispatch Number:
  &lt;asp:Label ID="DispatchNumberLabel" runat="server"&gt;&lt;/asp:Label&gt;
  &lt;p&gt;
  Terminal:
  &lt;asp:Label ID="TerminalLabel" runat="server"&gt;&lt;/asp:Label&gt;
  &lt;/p&gt;
  &lt;p&gt;
  Current
  Dispatch Info ID:
  &lt;asp:Label ID="DispatchInfoIdLabel" runat="server"&gt;&lt;/asp:Label&gt;
  &lt;/p&gt;
  &lt;p&gt;
  &amp;nbsp;Driver Name:
  &lt;asp:Label ID="DriverNameLabel" runat="server"&gt;&lt;/asp:Label&gt;
  &lt;/p&gt;
  &lt;asp:DropDownList ID="DriverDropDownList" runat="server" AutoPostBack="True" 
  DataSourceID="DriverListData" DataTextField="Select Driver" 
  DataValueField="Column1"&gt;
  &lt;/asp:DropDownList&gt;
  &lt;asp:SqlDataSource ID="DriverListData" runat="server" ConnectionString="&lt;%$ 
  ConnectionStrings:ConnectionString %&gt;" ProviderName="&lt;%$ 
  ConnectionStrings:ConnectionString.ProviderName %&gt;" SelectCommand="Select 
  '', 'Select Driver' as 'Select Driver'
  from Form_IntranetSharpTransit_DispatchInfo
  Union
  SELECT     DispatchInfoID, Driver + ' - ' + CAST(DispatchInfoID AS 
  varchar(50)) AS Expr1
  FROM         Form_IntranetSharpTransit_DispatchInfo 
  WHERE     (Dispatch = ?) AND (DaysOff NOT LIKE '%' + (SELECT DispatchDay 
  FROM Form_IntranetSharpTransit_DailyDispatch Where DailydispatchID = ?) + 
  '%') AND (Status LIKE 'Available')"&gt;
  &lt;SelectParameters&gt;
      &lt;asp:QueryStringParameter Name="?" QueryStringField="Theid" /&gt;
      &lt;asp:QueryStringParameter Name="?" QueryStringField="Theid" /&gt;
  &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
  AutoGenerateEditButton="True" DataSourceID="Store1Data" EditIndex="0" 
  OnSelectedIndexChanged="GridView1_SelectedIndexChanged"&gt;
  &lt;Columns&gt;
      &lt;asp:TemplateField HeaderText="Store 1:"&gt;
          &lt;EditItemTemplate&gt;
              &lt;asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" 
  OnTextChanged="TextBox1_TextChanged" Text='&lt;%# Bind("[Store Number]") %&gt;'&gt;
  &lt;/asp:TextBox&gt;
          &lt;/EditItemTemplate&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("[Store 
  Number]") %&gt;'&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  &lt;asp:SqlDataSource ID="Store1Data" runat="server" ConnectionString="&lt;%$ 
  ConnectionStrings:ConnectionString %&gt;" ProviderName="&lt;%$ 
  ConnectionStrings:ConnectionString.ProviderName %&gt;" SelectCommand="SELECT     
  (SELECT     Store
                     FROM          Form_IntranetSharpTransit_TourPlan
                     WHERE      (TourPlanID = 
  Form_IntranetSharpTransit_DispatchInfo_1.Store1)) AS 'Store Number', 
  Location1, Pro1, Store1Export
  FROM         Form_IntranetSharpTransit_DispatchInfo AS 
  Form_IntranetSharpTransit_DispatchInfo_1
  WHERE     (DispatchInfoID = ?)"&gt;
  &lt;SelectParameters&gt;
      &lt;asp:ControlParameter ControlID="DriverDropDownList" Name="?" 
  PropertyName="SelectedValue" /&gt;
  &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>All I want is to display the table with an edit button. When the edit button is clicked, I want the label in table to become an edit box (as my template shows). After the user has  modified the edit box, they can then click the update button, committing the change to the database and refreshing the table to show the changed values.</p>
  
  <p>This seems extremely simple but I have been struggling with it for about 3 months now.</p>
  
  <p>Please help.</p>