1

我是 PRADO 的新手,我有一个带有代码的文件 Home.page:

<%@ Title="Contact List" %>

<h1>Contact List</h1>

<a href="<%= $this->Service->constructUrl('insert')%>">Create New Contact</a>
<br/>
<com:TForm>
 <com:TDropDownList ID="personInfo">
  <com:TListItem Value="value 1" Text="item 1" />
  <com:TListItem Value="value 2" Text="item 2" Selected="true" />
  <com:TListItem Value="value 3" Text="item 3" />
  <com:TListItem Value="value 4" Text="item 4" />
 </com:TDropDownList>
</com:TForm>

& Home.php 带代码

<?php
class Home extends TPage
{
    /**
     * Populates the datagrid with user lists.
     * This method is invoked by the framework when initializing the page
     * @param mixed event parameter
     */
    public function onInit($param)
    {
        parent::onInit($param);
        // fetches all data account information
        $rec = ContactRecord::finder()->findAll();
    }
}
?>

$rec 包含所有值的数组。

现在我想在下拉列表中显示所有名称。我尽力了,但失败了。谁能帮我?谢谢

4

1 回答 1

2

您可以使用数据库表列名称填充下拉列表的 DataTextField 和 DataValueField,以分别用作 TListItem 的文本和值:

<?php
class Home extends TPage
{
    /**
     * Populates the datagrid with user lists.
     * This method is invoked by the framework when initializing the page
     * @param mixed event parameter
     */
    public function onInit($param)
    {
        parent::onInit($param);
        // fetches all data account information
        $rec = ContactRecord::finder()->findAll();
        $this->personInfo->DataSource = $rec;
        $this->personInfo->DataTextField = "columnNameToUseAsText";
        $this->personInfo->DataValueField = "columnNameToUseAsValue";
        $this->personInfo->DataBind();
    }
}
?>

或者,您可以在 HTML 前端执行此操作:

<com:TDropDownList ID="personInfo" DataTextField="columnNameToUseAsText" DataValueField="columnNameToUseAsValue" />

这样,您只需要在后端代码中指定DataSource属性并调用方法。DataBind()

于 2010-08-28T15:33:38.043 回答