【问题标题】:Show values in TDropDownList in PRADO在 PRADO 的 DropDownList 中显示值
【发布时间】:2011-02-21 07:13:19
【问题描述】:

我是 PRADO 的新手,我有一个文件 带有代码的主页:

<%@ 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 包含所有值的数组。

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

【问题讨论】:

    标签: php prado


    【解决方案1】:

    您可以使用数据库表列名称填充下拉列表的 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()方法即可。

    【讨论】:

      猜你喜欢
      • 2014-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多