Prado TDropDownList göster değerleri

1 Cevap php

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>

& Koduyla 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 tüm değerlerin dizi içerir.

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

1 Cevap

Sırasıyla TListItem metnin ve değer olarak kullanılacak veritabanı tablo sütun adları ile DropDownList DataTextField ve DataValueField doldurabilirsiniz:

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

Alternatif olarak, HTML ön sonunda bunu yapabilirsiniz:

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

Bu şekilde, sadece DataSource özelliğini belirtmek ve arka uç kod DataBind() yöntemini çağırmanız gerekir.