# How to configure a data source with a parameter based on a form field value from code-behind

**URL:** <https://discuss.workflowgen.com/t/how-to-configure-a-data-source-with-a-parameter-based-on-a-form-field-value-from-code-behind/291>\
**Category:** Form Designer\
**Created:** [November 5, 2015, 8:48am UTC](https://discuss.workflowgen.com/t/how-to-configure-a-data-source-with-a-parameter-based-on-a-form-field-value-from-code-behind/291 "2015-11-05T08:48:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wfg-admin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discuss.workflowgen.com/wfg-admin/32/714_2.png) [@wfg-admin](https://discuss.workflowgen.com/u/wfg-admin)\
**Post date:** [November 5, 2015, 8:48am UTC](https://discuss.workflowgen.com/t/how-to-configure-a-data-source-with-a-parameter-based-on-a-form-field-value-from-code-behind/291/1 "2015-11-05T08:48:09Z")

</div>

The sample process below shows how to configure a custom SQL datasource to populate a drop-down list.

The SQL datasource has a parameter named ID\_DIR in the SQL command WHERE clause. This parameter receives the selected value of the form’s REQUEST\_DIRECTORIES drop-down list.

It is possible to add multiple parameters to the same SQL command in this way.

```auto
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MainDbSource"].ToString();

  string providerName = System.Configuration.ConfigurationManager.ConnectionStrings["MainDbSource"].ProviderName;

  protected void Page_Load(object sender, EventArgs e)

  {

    base.Page_Load(sender, e);

    if(!IsPostBack)

    {

   	  // Configure directories data source

   	  SqlDataSource directoriesDataSource = new SqlDataSource();

   	  directoriesDataSource.ConnectionString = connectionString;

   	  directoriesDataSource.ProviderName = providerName;

   	  directoriesDataSource.SelectCommand = "SELECT ID_DIRECTORY, DIRNAME FROM DIRECTORY;";

   	  // Bind the dropdown list to the directories data source and set the value and text properties

   	  REQUEST_DIRECTORIES.DataSource = directoriesDataSource;

   	  REQUEST_DIRECTORIES.DataValueField = "ID_DIRECTORY";

  	    REQUEST_DIRECTORIES.DataTextField = "DIRNAME";

  	    REQUEST_DIRECTORIES.DataBind();  

  	    // Refresh users dropdown list

  	   RefreshUsersDropDownList();

    }

  }

  protected void DIRECTORY_CHANGED(object sender, EventArgs e)

  {

    // This method is called when the Directories DropDownListBox selection is changed

    RefreshUsersDropDownList(); 

  }

 

  private void RefreshUsersDropDownList()
  {

    // Configure users data source

    SqlDataSource usersDataSource = new SqlDataSource();

    usersDataSource.ConnectionString = connectionString;

    usersDataSource.ProviderName = providerName;

    usersDataSource.SelectCommand = "SELECT ID_USER, USERNAME FROM USERS WHERE ACTIVE = 'Y' AND ID_DIRECTORY = @ID_DIR";

    // Configure the ID_DIR parameter

    Parameter directoryParameter = new Parameter();

    directoryParameter.Name = "ID_DIR";

    directoryParameter.DefaultValue = REQUEST_DIRECTORIES.SelectedValue

    // Add the parameter to the SelectCommand parameters list

    usersDataSource.SelectParameters.Add(directoryParameter);

    // Bind the dropdown list to the users data source and set the value and text properties

    REQUEST_USERS.DataSource = usersDataSource;

    REQUEST_USERS.DataValueField = "ID_USER";
    REQUEST_USERS.DataTextField = "USERNAME";

    REQUEST_USERS.DataBind();

  }

```

---

<div class="post-metadata">

**Author:** ![GiapWeng](https://avatars.discourse-cdn.com/v4/letter/g/e36b37/32.png) [@GiapWeng](https://discuss.workflowgen.com/u/GiapWeng)\
**Post date:** [September 26, 2017, 7:15am UTC](https://discuss.workflowgen.com/t/how-to-configure-a-data-source-with-a-parameter-based-on-a-form-field-value-from-code-behind/291/2 "2017-09-26T07:15:27Z")

</div>

I use this method to populated the dropdownlist. But after I select a value and submit to next process. The value display was not the value that selected previously…

---

<div class="post-metadata">

**Author:** ![eddy.daouk](https://yyz2.discourse-cdn.com/flex030/user_avatar/discuss.workflowgen.com/eddy.daouk/32/672_2.png) [@eddy.daouk](https://discuss.workflowgen.com/u/eddy.daouk)\
**Post date:** [September 26, 2017, 9:41pm UTC](https://discuss.workflowgen.com/t/how-to-configure-a-data-source-with-a-parameter-based-on-a-form-field-value-from-code-behind/291/3 "2017-09-26T21:41:51Z")

</div>

Hi,

Please open a ticket on our helpdesk account so we can assist you in solving this issue.

Best Regards,  
Eddy.
