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 に答える