首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PRADO中显示TDropDownList格式的值

在PRADO中显示TDropDownList格式的值
EN

Stack Overflow用户
提问于 2010-05-19 17:37:21
回答 1查看 989关注 0票数 1

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

代码语言:javascript
复制
<%@ 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)

代码语言:javascript
复制
<?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包含所有值数组。

现在我想在下拉列表中显示所有的名字。我尽了最大的努力,但失败了。有谁可以帮我?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-28 23:33:38

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

代码语言:javascript
复制
<?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前端执行此操作:

代码语言:javascript
复制
<com:TDropDownList ID="personInfo" DataTextField="columnNameToUseAsText" DataValueField="columnNameToUseAsValue" />

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2864312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档