Creating a Store From CodeBehind

  1. #1

    Creating a Store From CodeBehind


    Creating a Store From CodeBehind

    Javascript error --> Store1 undefined

    Where is the code problem ??


    <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="ComboBoxDynamicStoreBind.aspx.cs"
        Inherits="ComboBoxDynamicStoreBind" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            
                <ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" SourceFormatting="True" />
               
                <ext:ComboBox ID="ComboBox1" runat="server" Mode="Local" Editable="false" ForceSelection="true"
                    TypeAhead="true" Select&#111;nfocus="true" DisplayField="CustomerName" ValueField="CustomerId"
                    EmptyText="Lütfen Seçiniz.." StoreID="Store1">
                </ext:ComboBox>
            
    
        </form>
    </body>
    </html>
    //Code Behind - Page Load
    protected void Page_Load(object sender, EventArgs e)
        {
            RecordField customerId = new RecordField("CustomerId");
            customerId.Mapping = "CustomerId";
            customerId.Type = RecordFieldType.Int;
    
            RecordField customerName = new RecordField("CustomerName");
            customerName.Mapping = "CustomerName";
            customerName.Type = RecordFieldType.String;
    
            ArrayReader arrayReader = new ArrayReader();
            arrayReader.ReaderID = "arrayReaderTest";
            arrayReader.Fields.Add(customerId);
            arrayReader.Fields.Add(customerName);
    
            Store store = new Store();
            store.ID = "Store1";
            this.form1.Controls.Add(store);
            store.Reader.Add(arrayReader);
            store.DataSource = new Customers().GetCustomersList(10);
            store.DataBind();
        }



    <!--Page Render HTML Code-->
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <!-- Coolite Toolkit for ASP.NET [Professional Edition]. Version 0.6.0.7019. -->
        <link rel="stylesheet" type="text/css" href="/CooliteDemo/extjs/resources/css/ext-all-embedded-css/coolite.axd" />
    <title>
        Untitled Page
    </title>
        <script type="text/javascript" src="/CooliteDemo/extjs/adapter/ext/ext-base-js/coolite.axd?7019"></script>
        <script type="text/javascript" src="/CooliteDemo/extjs/ext-all-debug-js/coolite.axd?7019"></script>
        <script type="text/javascript" src="/CooliteDemo/coolite/coolite-core-js/coolite.axd?7019"></script>
        <script type="text/javascript" src="/CooliteDemo/coolite/coolite-data-js/coolite.axd?7019"></script>
        <script type="text/javascript">
        //<![CDATA[
            Ext.onReady(function(){Ext.QuickTips.init();Coolite.Ext.ScriptManagerUniqueID='ScriptManager1';Coolite.Ext.ThisUrl='http://localhost:1471/CooliteDemo/ComboBoxDynamicStoreBind.aspx';this.Store1_Data=[{"CustomerId":1,"CustomerName":"Customer Name 0"},{"CustomerId":2,"CustomerName":"Customer Name 1"},{"CustomerId":3,"CustomerName":"Customer Name 2"},{"CustomerId":4,"CustomerName":"Customer Name 3"},{"CustomerId":5,"CustomerName":"Customer Name 4"},{"CustomerId":6,"CustomerName":"Customer Name 5"},{"CustomerId":7,"CustomerName":"Customer Name 6"},{"CustomerId":8,"CustomerName":"Customer Name 7"},{"CustomerId":9,"CustomerName":"Customer Name 8"},{"CustomerId":10,"CustomerName":"Customer Name 9"}];this.Store1=new Coolite.Ext.Store({
      id: "Store1",
      ajaxPostBackConfig: {
      formProxyArg: "form1"
    },
      reader: new Ext.data.ArrayReader({
      fields: [{
      type: "int",
      mapping: "CustomerId",
      name: "CustomerId"
    },{
      type: "string",
      mapping: "CustomerName",
      name: "CustomerName"
    }]
    }),
      autoLoad: true,
      serverID: "Store1"
    });this.Store1.proxy=new Ext.data.PagingMemoryProxy(Store1_Data, false);this.ComboBox1=new Ext.form.ComboBox({
      id: "ComboBox1",
      renderTo: "ComboBox1_Container",
      selectOnFocus: true,
      emptyText: "Lütfen Seçiniz..",
      store: Store1,
      valueField: "CustomerId",
      typeAhead: true,
      queryDelay: 10,
      mode: "local",
      hiddenName: "ComboBox1_Value",
      forceSelection: true,
      editable: false,
      displayField: "CustomerName",
      listeners: {
      render: {
      fn: function(el){el.getEl().dom.setAttribute("name","ComboBox1");}
    }
    },
      serverID: "ComboBox1"
    });});Ext.BLANK_IMAGE_URL="/CooliteDemo/extjs/resources/images/default/s-gif/coolite.axd";
        //]]>
        </script>
    </head>
    <body>
        <form name="form1" method="post" action="ComboBoxDynamicStoreBind.aspx" id="form1">
    
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2Mjk4NDI4MDAPZBYCAgMPZBYEAgEPZBYCZg8UKhJTeXN0ZW0uV2ViLlVJLlBhaXIBDwUJdnNNZW1iZXJzFCsAAQ8FBlJlYWRlchQrBAEPBQRiYXNlFgIeCFJlYWRlcklEBQ9hcnJheVJlYWRlclRlc3RkAgMPFCsEAQ8FCXZzTWVtYmVycxQrAAEPBQlMaXN0ZW5lcnMUKwABDwUGUmVuZGVyFCsEAQ8FBGJhc2UWAh4HSGFuZGxlcgUwZWwuZ2V0RWwoKS5kb20uc2V0QXR0cmlidXRlKCJuYW1lIiwiQ29tYm9Cb3gxIik7ZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAgUOU2NyaXB0TWFuYWdlcjEFCUNvbWJvQm94MVaWes/UOgP8uGKmRRi/8d2tulnl" />
    
    
    
    <script type="text/javascript">
    //<![CDATA[
    var theForm = &#100;ocument.forms['form1'];
    if (!theForm) {
        theForm = &#100;ocument.form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script>
    
    
            
                
               
                <div id="ComboBox1_Container" style="display:inline;">
    
    
    
            
    
        </form>
    </body>
    </html>
  2. #2

    RE: Creating a Store From CodeBehind

    Hi,

    The Store must created before any control which used this Store. Try to add PlaceHolder before Combo and add Store to this placeholder.


  3. #3

    RE: Creating a Store From CodeBehind

    hi,

    <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="ComboBoxDynamicStoreBind.aspx.cs"
        Inherits="ComboBoxDynamicStoreBind" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            
                <ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" SourceFormatting="True" />
                <asp:PlaceHolder ID="PlaceHolder1" runat="server">
                </asp:PlaceHolder>
            
    
        </form>
    </body>
    </html>
    protected void Page_Load(object sender, EventArgs e)
        {
            RecordField customerId = new RecordField("CustomerId");
            customerId.Mapping = "CustomerId";
            customerId.Type = RecordFieldType.Int;
    
            RecordField customerName = new RecordField("CustomerName");
            customerName.Mapping = "CustomerName";
            customerName.Type = RecordFieldType.String;
    
            
            Store store = new Store();
            store.ID = "Store1";
            store.Reader.Add(new ArrayReader());
            store.Reader.Reader.Fields.Add(customerId);
            store.Reader.Reader.Fields.Add(customerName);
            store.DataSource = new Customers().GetCustomersList(10);
            store.DataBind();
    
            this.PlaceHolder1.Controls.Add(store);
    
            ComboBox comboBox = new ComboBox();
            comboBox.ID = "combo1";
            comboBox.Mode = DataLoadMode.Local;
            comboBox.Editable = false;
            comboBox.ForceSelection = true;
            comboBox.TypeAhead = true;
            comboBox.SelectOnFocus = true;
            comboBox.StoreID = store.ID;
            comboBox.DisplayField = "CustomerName";
            comboBox.ValueField = "CustomerId";
            this.PlaceHolder1.Controls.Add(comboBox);
    
        }

    please sample ,I am easy speak english
  4. #4

    RE: Creating a Store From CodeBehind

    Hi,

    Your last code works correct for me. What sample do you need?
    If you create dynamically Store and Combo then it is not required Placeholder, just add Store first to form controls and then Combo.

    Here is my test code which I used when suggested PlaceHolder:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
        
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                RecordField customerId = new RecordField("CustomerId");
                customerId.Mapping = "CustomerId";
                customerId.Type = RecordFieldType.Int;
    
                RecordField customerName = new RecordField("CustomerName");
                customerName.Mapping = "CustomerName";
                customerName.Type = RecordFieldType.String;
    
                ArrayReader arrayReader = new ArrayReader();
                arrayReader.ReaderID = "arrayReaderTest";
                arrayReader.Fields.Add(customerId);
                arrayReader.Fields.Add(customerName);
    
                Store store = new Store();
                store.ID = "Store1";
                Holder1.Controls.Add(store);
                store.Reader.Add(arrayReader);
                //store.DataSource = new Customers().GetCustomersList(10);
                store.DataBind();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            
                <ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" SourceFormatting="True" />
                
                <asp:PlaceHolder ID="Holder1" runat="server"></asp:PlaceHolder>
               
                <ext:ComboBox ID="ComboBox1" runat="server" Mode="Local" Editable="false" ForceSelection="true"
                    TypeAhead="true" Select&#111;nfocus="true" DisplayField="CustomerName" ValueField="CustomerId"
                    EmptyText="Lütfen Seçiniz.." StoreID="Store1">
                </ext:ComboBox>
            
    
        </form>
    </body>
    </html>

  5. #5

    RE: Creating a Store From CodeBehind

    hi,

    Sample code not run but I can RecordFieldType Remove make sample code run

    my culture tr-TR

                RecordField customerId = new RecordField("CustomerId");
    
                customerId.Mapping = "CustomerId";
    
                customerId.Type = RecordFieldType.Int;
    
    
     reader: new Ext.data.ArrayReader({
      fields: [{
      type: "int", -- bug ----- > not correct : int ---> correct : int 
      mapping: "CustomerId",
      name: "CustomerId"

    thank you
  6. #6

    RE: Creating a Store From CodeBehind

    Hi,

    I was able reproduce this bug when set Culture="tr-TR". It will be fixed soon
    Thanks for the bug pointing


Similar Threads

  1. [CLOSED] Creating Combobox + Store in CodeBehind
    By trezv in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 12, 2015, 1:41 PM
  2. [CLOSED] Creating ext:Window in CodeBehind.Button aligment
    By supera in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 09, 2012, 10:13 AM
  3. [CLOSED] Creating and Show ext.Window in CodeBehind
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 08, 2012, 3:31 PM
  4. [CLOSED] Creating DirectEvent from codebehind
    By krzak in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 10:17 AM
  5. Creating a delux portal from codebehind.
    By prashobkumar in forum 1.x Help
    Replies: 1
    Last Post: Dec 09, 2008, 11:36 AM

Posting Permissions