# populate\_datalist

`populate_datalist` function has 1 variants:

{% tabs %}
{% tab title="Variant 1" %}

#### Declaration <a href="#declaration" id="declaration"></a>

```
void populate_datalist(char dataListName, recordset rs);
```

#### Description

1. [\<datalist>\</datalist>](https://muradkarakas.gitbook.io/sodium_documentation/language-reference/built-in-functions/sodium-built-in-functions/other-functions/broken-reference) tag is needed in [the form file](https://muradkarakas.gitbook.io/sodium_documentation/language-reference/built-in-functions/sodium-built-in-functions/other-functions/broken-reference).
2. `populate_datalist` function fills the data list by using a select query result. Record set variable is used as a reference to `select` statement.
3. &#x20;There is no restriction on sql select query command column names and count. However, the `select` statement must have at least 2 columns named as `label` and `value`.
4. Other columns are added to each option tag of the data list tag as additional attribute and used to filter values for a specific look up item value.
5. If you use "lookup-item-name" in a select tag, your data list (declared in "datalist-name" of that select tag) must have additional attribute with the same name (declared in "lookup-item-name").

#### Parameters

`char dataListName`

`recordset rs`

#### Return Value <a href="#return-value" id="return-value"></a>

#### Example <a href="#example" id="example"></a>

Frmx file

```
<datalist id="provinces"></datalist>
 
<datalist id="counties"></datalist>
 
<controlblock control-block-name="cb1">
 <select style="width: 100px" name="province_id"
    datalist-name="provinces">
 </select>
</controlblock>
 
<controlblock control-block-name="cb2">
 <select style="width: 100px" name="county_id" datalist-name="counties"
    lookup-item-block-name="cb1" lookup-item-name="province_id">
 </select>
</controlblock>
```

Sqlx file

```
void page.load() {
        rsProvinces =   select province_name label, province_id value
                                        from
                                                provinces
                                        order by
                                          province_name;
        populate_datalist('provinces', rsProvinces);
 
        rsCounties =    select county_name label, county_id value, province_id province_id
                                        from
                                                counties
                                        order by
                                          county_name;
        populate_datalist('counties', rsCounties);
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://muradkarakas.gitbook.io/sodium_documentation/language-reference/built-in-functions/sodium-built-in-functions/other-functions/populate_datalist.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
