title: How to save option selected in Dropdownlist after selection
body: <p>I am displaying columns in a GridView and one of the columns is a dropdownlist. I want to be able to save the option selected in the dropdownlist as soon as something is selected. I have done this with one of the columns that has a textbox so I was hoping to do something similar with the DropDownList.
  The code for the textbox and dropdownlist:</p>
  
  <pre><code>protected void gvPieceDetails_ItemDataBound(object sender, GridViewRowEventArgs e) {
      if (e.Row.RowType == DataControlRowType.DataRow) {
          JobPieceSerialNo SerNo = e.Row.DataItem as JobPieceSerialNo;
          if (SerNo != null) {
              TextBox txtComment = e.Row.FindControl("txtComment") as TextBox;
              txtComment.Text = SerNo.Comment;
              txtComment.Attributes.Add("onblur", "UpdateSerialComment(" + SerNo.ID.ToString() + ", this.value);");
  
              DropDownList ddlReasons = (e.Row.FindControl("ddlReasons") as DropDownList);
              DataSet dsReasons = DataUtils.GetUnapprovedReasons(Company.Current.CompanyID, "", true, "DBRIEF");
              ddlReasons.DataSource = dsReasons;
              ddlReasons.DataTextField = "Description";
              ddlReasons.DataValueField = "Description";
              ddlReasons.DataBind();
  
              ddlReasons.Items.Insert(0, new ListItem("Reason"));
  
          }
      }
  </code></pre>
  
  <p>How to I create an update function for a dropdownlist?</p>
  
  <pre><code>protected void DDLReasons_SelectedIndexChanged(object sender, EventArgs e)
      {
          string sel = ddlReasons.SelectedValue.ToString();
      }
  
      public static void UpdateSerialReason(int SerNoID, string Reasons)
      {
          JobPieceSerialNo SerNo = new JobPieceSerialNo(SerNoID);
          SerNo.Reason = sel; //can't find sel value 
          SerNo.Update();
      }
  </code></pre>
  
  <p>Dropdownlist:</p>
  
  <pre><code> &lt;asp:DropDownList ID="ddlReasons" runat="server" OnSelectedIndexChanged="DDLReasons_SelectedIndexChanged" AutoPostBack="true"&gt;&lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>I created an OnSelectedIndexChanged function to get the selected value. But how do I then save that value? Is there a way to pass it into the UpdateSerialReason function?</p>