我是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包含所有值的数组。
现在我想在下拉列表中显示所有名称。我尽我所能但失败了。 谁能帮我? 感谢
答案 0 :(得分: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()
方法。