在 PRADO 中显示 TdropDownList 中的值

发布于 2024-09-01 18:06:16 字数 1123 浏览 5 评论 0原文

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

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

I m new to PRADO, I have a file
Home.page with code:

<%@ 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 with code

<?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();
    }
}
?>

the $rec contain array of all values.

Now I want to show all name in Dropdown list. I tried my best but fail.
Can anyone help me?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又怨 2024-09-08 18:06:16

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

You can populate the DataTextField and DataValueField of the dropdownlist with the database table column names to use as the TListItem's text and value respectively:

<?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();
    }
}
?>

Alternatively, you can do it in the HTML front-end:

<com:TDropDownList ID="personInfo" DataTextField="columnNameToUseAsText" DataValueField="columnNameToUseAsValue" />

This way, you only need to specify the DataSource property and call the DataBind() method in your back-end code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文