# How to set the stored value to a dropdown list when the dropdown has a databinding happening during page load?

**URL:** <https://discuss.workflowgen.com/t/how-to-set-the-stored-value-to-a-dropdown-list-when-the-dropdown-has-a-databinding-happening-during-page-load/157>\
**Category:** Visual Studio Web Forms\
**Created:** [March 17, 2008, 7:47am UTC](https://discuss.workflowgen.com/t/how-to-set-the-stored-value-to-a-dropdown-list-when-the-dropdown-has-a-databinding-happening-during-page-load/157 "2008-03-17T07:47:00Z")\
**Posts on this page:** 2\
**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:** [March 17, 2008, 7:47am UTC](https://discuss.workflowgen.com/t/how-to-set-the-stored-value-to-a-dropdown-list-when-the-dropdown-has-a-databinding-happening-during-page-load/157/1 "2008-03-17T07:47:00Z")

</div>

### Issue

WorkflowGen assigns values to your form fields **before** the `Page_Load` event occurs, so any databinding of a drop-down list (e.g. read values from database) that happens in your `Page_load` section will reset the selected value.

### Solution

**After** you have re-bound your combo box (i.e., your combo box has been re-populated with the options you retrieved from an external source), you must set the originally selected value manually.

After your `DropDownList` databinding method is called, run the below method by passing the target `DropDownList` as a parameter.

Add this method in your code:

**C#**

```auto
private void SetDropDownListSelectedValue(DropDownList TargetDDL)
{ 
   if (TargetDDL != null) { 
      string WFGFieldName = TargetDDL.ID; 
      string SelectedValue = FormData.Tables[Table1].Rows[0][WFGFieldName].ToString(); 
      ListItem li = null; 
      li = TargetDDL.Items.FindByValue(SelectedValue); 
      if (li != null) { 
        int index = TargetDDL.Items.IndexOf(li); TargetDDL.SelectedIndex = index; 
      }
 }
}

```

**VB**

```auto
Private Sub SetDropDownListSelectedValue(ByVal TargetDDL As DropDownList) 
 If ((Not (TargetDDL) Is Nothing)) Then
  Dim WFGFieldName As String = TargetDDL.ID 
  Dim SelectedValue As String = FormData.Tables(Table1).Rows(0)(WFGFieldName).ToString 
  Dim li As ListItem = Nothing 
  li = TargetDDL.Items.FindByValue(SelectedValue) 
  If (Not (li) Is Nothing) Then
   Dim index As Integer = TargetDDL.Items.IndexOf(li) 
   TargetDDL.SelectedIndex = index 
  End If
 End If
End Sub

```

---

<div class="post-metadata">

**Author:** ![nvarlet](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@nvarlet](https://discuss.workflowgen.com/u/nvarlet)\
**Post date:** [August 17, 2020, 9:28am UTC](https://discuss.workflowgen.com/t/how-to-set-the-stored-value-to-a-dropdown-list-when-the-dropdown-has-a-databinding-happening-during-page-load/157/2 "2020-08-17T09:28:38Z")

</div>

Hello,

> [@wfg-admin](#):
>
> `string SelectedValue = FormData.Tables[Table1].Rows[0][WFGFieldName].ToString();`

It works when you add quotes to Table1

string SelectedValue = FormData.Tables[“Table1”].Rows[0][WFGFieldName].ToString();
