我是普拉多的新手,我有一个带有代码的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 (&S)
<?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包含所有值数组。
现在我想在下拉列表中显示所有的名字。我尽了最大的努力,但失败了。有谁可以帮我?谢谢
发布于 2010-08-28 23:33:38
您可以使用数据库表列名称填充dropdownlist的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()方法。
https://stackoverflow.com/questions/2864312
复制相似问题