Help Bind Field

  1. #1

    Help Bind Field

    Tell please, as bind a field with store?
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAll"
            TypeName="classDB.News_DB" />
    
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetAllForNews"
            TypeName="classDB.Persons_DB" />
    
     <ext:Store ID="StorePerson" runat="server" DataSourceID="ObjectDataSource2">
            <Reader>
                <ext:JsonReader IDProperty="PersonsID">
                    <Fields>
                        <ext:RecordField Name="PersonsID" Type="Int" />
                        <ext:RecordField Name="PersonsFirsname" />
                        <ext:RecordField Name="PersonsName" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
    
     <ext:GridPanel ID="GridPanel1" runat="server" Title="Новости" Frame="true" AutoWidth="true">
                    <Store>
                        <ext:Store ID="Store1" runat="server" DataSourceID="ObjectDataSource1">
                            <Reader>
                                <ext:JsonReader IDProperty="NewsID">
                                    <Fields>
                                        <ext:RecordField Name="NewsID" />
                                        <ext:RecordField Name="NewsDescription" />
                                        <ext:RecordField Name="NewsText" />
                                        <ext:RecordField Name="NewsDateTime" Type="Date" />
                                        <ext:RecordField Name="NewsTitle" />
                                        <ext:RecordField Name="NewsAuthorPersonsID" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <ColumnModel ID="ColumnModel2" runat="server">
                        <Columns>
                            <ext:DateColumn DataIndex="NewsDateTime" Width="20" Header="Дата/время публикации"
                                Format="dd.MM.yyyy HH:mm" />
                            <ext:Column Header="Тема" Width="50" DataIndex="NewsTitle" />
                            <ext:Column Header="Описание" DataIndex="NewsDescription" />
                            <ext:Column Header="Автор" Width="30" DataIndex="NewsAuthorPersonsID" />
                        </Columns>
                    </ColumnModel>
                    <View>
                        <ext:GridView ID="GridView2" runat="server" ForceFit="true" />
                    </View>
                    <SelectionModel>
                        <ext:RowSelectionModel ID="RowSelectionModel2" runat="server" />
                    </SelectionModel>
                    <Plugins>
                        <ext:RowExpander ID="RowExpander1" runat="server">
                            <Template ID="Template1" runat="server">
                                <Html>
                                    <p><b>Текст новости:</b> {NewsText}</p>
                                    <br />
                                </Html>
                            </Template>
                        </ext:RowExpander>
                    </Plugins>
                    <BottomBar>
                        <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" DisplayInfo="true"
                            DisplayMsg="Показаны записи {0} - {1} из {2}" EmptyMsg="Записи отсутствуют" />
                    </BottomBar>
                </ext:GridPanel>
    need that instead of NewsAuthorPersonsID it was substituted PersonsFirsname+PersonsName

    p.s. sorry for my curve engish
  2. #2
    Hi,

    Just use Renderer for the Column
    <ext:Column Header="Автор" Width="30" DataIndex="NewsAuthorPersonsID">
        <Renderer Fn="showPerson" />
    </ext:Column>
    
    function showPerson (value) {
        if(!Ext.isEmpty(value)){
            var record = StorePerson.getById(value);
            if(record){
               return record.get("PersonsFirsname") + " " + record.get("PersonsName");
            }
       
            return "Such person is not found";
        }
    
        return "";
    }
  3. #3
    Does not work :|
  4. #4
    Hi,

    What doesn't work? Please provide more details and full test sample
  5. #5
    Quote Originally Posted by Daimon View Post
    Does not work :|
    Please do not respond with "Does not work". That does not help.
    Geoffrey McGill
    Founder
  6. #6
    full page .aspx
    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
        CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
        Новости
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentMain" runat="Server">
        <asp:ObjectDataSource ID="ObjectDataSource1News" runat="server" SelectMethod="GetAll"
            TypeName="classDB.News_DB" />
        <asp:ObjectDataSource ID="ObjectDataSourcePersons" runat="server" SelectMethod="GetAllForNews"
            TypeName="classDB.Persons_DB" />
        <style type="text/css">
            .x-grid3-td-fullName .x-grid3-cell-inner
            {
                font-family: tahoma, verdana;
                display: block;
                font-weight: normal;
                font-style: normal;
                color: #385F95;
                white-space: normal;
            }
            
            .x-grid3-row-body p
            {
                margin: 5px 5px 10px 5px !important;
                width: 99%;
                color: Gray;
                font-size: 13px;
            }
        </style>
        <script type="text/javascript">
            function showPerson(value) {
                if (!Ext.isEmpty(value)) {           
                    var record = StorePerson.getById(value);
                    if (record) {
                        return record.get("PersonsFirsname") + " " + record.get("PersonsName");
                    }
    
                    return "Such person is not found";
                }
    
                return "";
            }     
        </script>
        <ext:Store ID="StorePerson" runat="server" DataSourceID="ObjectDataSourcePersons">
            <Reader>
                <ext:JsonReader IDProperty="PersonsID">
                    <Fields>
                        <ext:RecordField Name="PersonsID" />
                        <ext:RecordField Name="PersonsFirsname" />
                        <ext:RecordField Name="PersonsName" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        <ext:FitLayout runat="server">
            <Items>
                <ext:GridPanel ID="GridPanel1" runat="server" Title="Новости" Frame="true" AutoWidth="true">
                    <Store>
                        <ext:Store ID="StoreNews" runat="server" DataSourceID="ObjectDataSource1News">
                            <Reader>
                                <ext:JsonReader IDProperty="NewsID">
                                    <Fields>
                                        <ext:RecordField Name="NewsID" />
                                        <ext:RecordField Name="NewsDescription" />
                                        <ext:RecordField Name="NewsText" />
                                        <ext:RecordField Name="NewsDateTime" Type="Date" />
                                        <ext:RecordField Name="NewsTitle" />
                                        <ext:RecordField Name="NewsAuthorPersonsID" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <ColumnModel ID="ColumnModel2" runat="server">
                        <Columns>
                            <ext:DateColumn DataIndex="NewsDateTime" Width="20" Header="Дата/время публикации"
                                Format="dd.MM.yyyy HH:mm" />
                            <ext:Column Header="Тема" Width="50" DataIndex="NewsTitle" />
                            <ext:Column Header="Описание" DataIndex="NewsDescription" />
                            <ext:Column Header="Автор" Width="30" DataIndex="NewsAuthorPersonsID">
                                <Renderer Fn="showPerson" />
                            </ext:Column>
                        </Columns>
                    </ColumnModel>
                    <View>
                        <ext:GridView ID="GridView2" runat="server" ForceFit="true" />
                    </View>
                    <SelectionModel>
                        <ext:RowSelectionModel ID="RowSelectionModel2" runat="server" />
                    </SelectionModel>
                    <Plugins>
                        <ext:RowExpander ID="RowExpander1" runat="server">
                            <Template ID="Template1" runat="server">
                                <Html>
                                    <p><b>Текст новости:</b> {NewsText}</p>
                                    <br />
                                </Html>
                            </Template>
                        </ext:RowExpander>
                    </Plugins>
                    <BottomBar>
                        <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" DisplayInfo="true"
                            DisplayMsg="Показаны записи {0} - {1} из {2}" EmptyMsg="Записи отсутствуют" />
                    </BottomBar>
                </ext:GridPanel>
            </Items>
        </ext:FitLayout>
    </asp:Content>
    public class Persons_DetailsShort
        {
            private int personsID;
            public int PersonsID
            {
                get { return personsID; }
                set { personsID = value; }
            }
    
            private string personsFirsname;
            public string PersonsFirsname
            {
                get { return personsFirsname; }
                set { personsFirsname = value; }
            }
    
            private string personsName;
            public string PersonsName
            {
                get { return personsName; }
                set { personsName = value; }
            }
    
    
            public Persons_DetailsShort(
                int _PersonsID,
                string _PersonsFirsname,
                string _PersonsName           
                )
            {
                personsID = _PersonsID;
                personsFirsname = _PersonsFirsname;
                personsName = _PersonsName;          
            }
        }
     public class Persons_DB
        {
            private string connectionString;
    
            public Persons_DB()
            {
                connectionString = WebConfigurationManager.ConnectionStrings["NTRDB"].ConnectionString;
            }
            public List<Persons_DetailsShort> GetAllForNews()
            {
                SqlConnection con = new SqlConnection(connectionString);
                SqlCommand cmd = new SqlCommand("Persons_GetAllForNews", con);
                cmd.CommandType = CommandType.StoredProcedure;
    
                List<Persons_DetailsShort> PersonsList_ALL = new List<Persons_DetailsShort>();
                try
                {
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Persons_DetailsShort Persons_LIST = new Persons_DetailsShort(
                (int)reader["PersonsID"],
                (string)reader["PersonsFirsname"],
                (string)reader["PersonsName"]
                    );
                        PersonsList_ALL.Add(Persons_LIST);
                    }
                    reader.Close();
                    return PersonsList_ALL;
                }
                catch (SqlException err)
                {
                    throw new ApplicationException("Ошибка данных. Ошибка в классе Persons_DB, матод GetAllForNews");
                }
                finally
                {
                    con.Close();
                }
            }
    }
    if used :
    function showPerson(value) {
                if (!Ext.isEmpty(value)) {           
                    var record = StorePerson.getById(value);
                    if (record) {
                        return record.get("PersonsFirsname") + " " + record.get("PersonsName");
                    }
    
                    return "Such person is not found";
                }
    
                return "";
            }
    nothing displayed

    i think problem in StorePerson.getById(value);
    because edit on
    function showPerson(value) {
                if (!Ext.isEmpty(value)) {  
                 return value         
                    var record = StorePerson.getById(value);
                    if (record) {
                        return record.get("PersonsFirsname") + " " + record.get("PersonsName");
                    }
    
                    return "Such person is not found";
                }
    
                return "";
            }
    displayed ID
    Last edited by Daniil; Dec 01, 2010 at 8:10 PM. Reason: Please wrap any code in [CODE] tags
  7. #7
    how to solve the problem?
  8. #8
    I solved this problem,
    adding IDMode="Static" in store :)

Similar Threads

  1. Replies: 2
    Last Post: Sep 22, 2011, 11:46 AM
  2. Replies: 2
    Last Post: Aug 19, 2011, 1:36 PM
  3. [CLOSED] How to "bind" a ComboBox to a field in a FormPanel
    By mattwoberts in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Jan 11, 2011, 10:22 AM
  4. Replies: 2
    Last Post: Feb 17, 2010, 9:47 AM
  5. how to bind ....
    By izee in forum 1.x Help
    Replies: 0
    Last Post: Mar 23, 2009, 12:32 AM

Posting Permissions