Generating Combobox items.

  1. #1

    Generating Combobox items.

    I am quite stuck with generating combobox ListItems from code behind. I am basically trying to generate a combobox with days in a month. From the debug mode on VS I can see that the line ddlPublicationDays.Item.Add(new coolite.Web.ListItem(i.ToString(), i.ToString())) is being read and processed, however, the combobox does not return anything at all.

    The Code Behind:
    
     for (int i = 1; i <= 31; i++)
            {
             
                ddlPublicationDays.Items.Add(new Coolite.Ext.Web.ListItem(i.ToString(), i.ToString()));
            }
    The Combobox:
    <ext:ComboBox runat="server" ID="ddlPublicationDays" Width="60" />
    I am not sure what I am missing.

    I appreciate any help at all.
  2. #2
    Hi,

    Please provide full test sample (please note that Items collection cannot be changed during AjaxEvent, if you need to set new items during AjaxEvent then use Store control)

    Here is my test case
    <%@ Page Language="C#"  %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 1; i <= 31; i++)
            {
                ddlPublicationDays.Items.Add(new Coolite.Ext.Web.ListItem(i.ToString(), i.ToString()));
            }
        }
    </script>
     
    <!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>
        </title>
    </head>
    <body>
        <ext:ScriptManager ID="ResourceManager1" runat="server" />
        <ext:ComboBox runat="server" ID="ddlPublicationDays" Width="60" />
    </body>
    </html>
  3. #3
    Hi vladimir,

    Thank you for the quick reply.

    Your test case is exactly how I have my code setup. Below is most of the code on my pages.

    I did think about using store but I thought that would be a little more work adding items to a store through a for loop. Anyways, I will give that a try again.

    
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="EditPublicationDetails.ascx.cs" Inherits="EditPublicationDetails" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <link href="Styles/Site.css" rel="stylesheet" type="text/css" />
    
        <ext:Store ID="StorePublicationType" runat="server" AutoLoad="false">
                <Reader>
                    <ext:JsonReader ReaderID="PublicationTypeCode">
                        <Fields>
                            <ext:RecordField Name="PublicationTypeName" />
                            <ext:RecordField Name="PublicationTypeCode" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>            
        </ext:Store>
    
        <ext:Store ID="StoreSubPublicationType" runat="server">
                <Reader>
                    <ext:JsonReader ReaderID="SubPublicationTypeCode">
                        <Fields>
                            <ext:RecordField Name="SubPublicationTypeName" />
                            <ext:RecordField Name="SubPublicationTypeCode" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>           
        </ext:Store>
        
    <ext:Window
        id="EditPublicationWindow"
        runat="server" 
        Icon="ApplicationFormEdit"
        Title="Edit Publication Details"
        Width="550" 
        Height="350" 
        AutoShow="false" 
        Modal="true" 
        Hidden="true"
        Layout="Fit"
        AutoScroll="true"> 
       
        <Body>  
            <ext:Panel 
                    runat="server" 
                    ID="pnlEditPanel" 
                    Padding="5"
                    Layout="Form">
                    <Body>                   
                        <div class="padding">
                             <ext:Panel Cls="block" id="divPublicationTypes" runat="server" Border="false">
                                <Body>
                                <span class="editLabel">
                                    <ext:Label Text="Publication Type: " ID="lblPublicationTypes" runat="server" />
                                </span>
                                <div class="editParameter">
                                    <ext:ComboBox ID="ddlPublicationTypes" 
                                                  runat="server" 
                                                  StoreID="StorePublicationType" 
                                                  ValueField="PublicationTypeCode" 
                                                  DisplayField="PublicationTypeName" 
                                                  Width="150">
                                    </ext:ComboBox>
                                </div>
                                </Body>
                            </ext:Panel>
    
                             <ext:Panel Cls="block" id="divSubPublicationTypes" runat="server" Border="false">
                                <Body>
                                <span class="editLabel">
                                    <ext:Label Text="Sub-Publication Type: " ID="lblSubPublication" runat="server" />
                                </span>
                                <div class="editParameter">
                                    <ext:ComboBox ID="ddlSubPublicationTypes" 
                                                  runat="server" 
                                                  StoreID="StoreSubPublicationType"
                                                  ValueField="SubPublicationTypeCode"
                                                  DisplayField="SubPublicationTypeName"
                                                  Width="150" />
                                </div>
                                </Body>
                            </ext:Panel>
                                                      
                            <ext:Panel Cls="block" id="divStartDate" runat="server" Border="false">
                                <Body>
                                <span class="editLabel">
                                    <ext:Label ID="lblStartDate" runat="server" Text="Start Date: " />
                                </span>
                                <div class="editParameter">
                                    <ext:ComboBox runat="server" ID="ddlPublicationMonths" Width="100">
                                        <Items>
                                            <ext:ListItem Text=" " Value="0"></ext:ListItem>
                                            <ext:ListItem Text="January" Value="1"></ext:ListItem>
                                            <ext:ListItem Text="February" Value="2"></ext:ListItem> 
                                            <ext:ListItem Text="March" Value="3"></ext:ListItem>
                                            <ext:ListItem Text="April" Value="4"></ext:ListItem> 
                                            <ext:ListItem Text="May" Value="5"></ext:ListItem> 
                                            <ext:ListItem Text="June" Value="6"></ext:ListItem> 
                                            <ext:ListItem Text="July" Value="7"></ext:ListItem> 
                                            <ext:ListItem Text="August" Value="8"></ext:ListItem>
                                            <ext:ListItem Text="September" Value="9"></ext:ListItem> 
                                            <ext:ListItem Text="October" Value="10"></ext:ListItem>
                                            <ext:ListItem Text="November" Value="11"></ext:ListItem>
                                            <ext:ListItem Text="December" Value="12"></ext:ListItem>
                                        </Items>
                                    </ext:ComboBox>
                                </div>
                                <div class="editParameter">
                                    <ext:ComboBox runat="server" ID="ddlPublicationDays" Width="50">
                                    </ext:ComboBox>
                                </div>
                                <div class="editParameter">
                                    <ext:ComboBox runat="server" ID="ddlPublicationYears" Width="60">  
                                    </ext:ComboBox>
                                </div>
                                </Body>
                            </ext:Panel>
    
                            <ext:Panel Cls="block" id="divEndDate" runat="server" Border="false">
                                <Body>
                                <span class="editLabel">
                                    <ext:Label runat="server" Text="End Date: " ID="lblEndDate" />
                                </span>
                                <div class="editParameter">
                                    <ext:ComboBox runat="server" ID="ddlEndPublicationMonths" Width="100">
                                        <Items>
                                            <ext:ListItem Text=" " Value="0"></ext:ListItem>
                                            <ext:ListItem Text="January" Value="1"></ext:ListItem>
                                            <ext:ListItem Text="February" Value="2"></ext:ListItem> 
                                            <ext:ListItem Text="March" Value="3"></ext:ListItem>
                                            <ext:ListItem Text="April" Value="4"></ext:ListItem> 
                                            <ext:ListItem Text="May" Value="5"></ext:ListItem> 
                                            <ext:ListItem Text="June" Value="6"></ext:ListItem> 
                                            <ext:ListItem Text="July" Value="7"></ext:ListItem> 
                                            <ext:ListItem Text="August" Value="8"></ext:ListItem>
                                            <ext:ListItem Text="September" Value="9"></ext:ListItem> 
                                            <ext:ListItem Text="October" Value="10"></ext:ListItem>
                                            <ext:ListItem Text="November" Value="11"></ext:ListItem>
                                            <ext:ListItem Text="December" Value="12"></ext:ListItem>
                                        </Items>
                                    </ext:ComboBox>
                                </div>
                                <div class="editParameter">
                                    <ext:ComboBox runat="server" ID="ddlEndPublicationDays" DisplayField="Value" Width="50">
                                    </ext:ComboBox>
                                </div>
                                <div class="editParameter">
                                    <ext:ComboBox runat="server" ID="ddlEndPublicationYears" Width="60">  
                                    </ext:ComboBox>
                                </div>
                                </Body>
                            </ext:Panel>                 
                        </div>
                    </Body>
            </ext:Panel>
        </Body>
    
        <Buttons>
            <ext:Button ID="SaveButton" runat="server" Text="Save" Icon="Disk">
                <AjaxEvents>
                    <Click OnEvent="SavePublicationEdit" Failure="Ext.MessageBox.alert('Saving failed', 'Error during ajax event');">
                        <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{EditPublicationWindow}.body}" />
                        <ExtraParams>
                            <ext:Parameter Name="id" Value="#{PublicationID}.getValue()" Mode="Raw" />
                        </ExtraParams>
                    </Click>
                </AjaxEvents>
            </ext:Button>
            <ext:Button ID="CancelButton" runat="server" Text="Cancel" Icon="Cancel">
                <Listeners>
                    <Click Handler="#{EditPublicationWindow}.hide(null);" />
                </Listeners>
            </ext:Button>
        </Buttons>
    
    
    </ext:Window>

    CODE BEHIND
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class EditPublicationDetails : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.EditPublicationWindow.Hide();
        }
    
        // Setup the Edit Window
        public void SetupEditWIndow(Int32 pubID)
        {
            this.txtPublicationID.Text = pubID.ToString();
            
            PublicationBLL publicationBLL = new PublicationBLL();
            Publication editPublication = new Publication();
            editPublication = publicationBLL.getPublicationByID(pubID);
            
            if (editPublication != null)
            {
                pnlEditPanel.Visible = true;
                hideAllPanels();
                fillPublicationTypeDropDown();
                
                if (editPublication.SubPublicationTypeCode.Trim().ToString() != "")
                {
                    String publicationCode = editPublication.SubPublicationTypeCode.Trim().ToString();
                    getAttributes(publicationCode);
                    ChangeLabels(publicationCode);
    
                    String parentPublicationCode = editPublication.PublicationTypeCode.Trim().ToString();
                    // Sub Publication DDL is generate from the value of the Publication Type
                    fillSubPublicationTypeDropDown(parentPublicationCode, publicationCode);
                    divSubPublicationTypes.Hidden = false;
                }
                else
                {
                    divSubPublicationTypes.Hidden = true;
                    String publicationCode = editPublication.PublicationTypeCode.ToString();
                    getAttributes(publicationCode);
                    ChangeLabels(publicationCode);
                }
    
                assignPublicationValues(editPublication);
                fillDateDropDowns();
            }
            else
            {
                this.EditPublicationWindow.Hide();
            }
        }
    
        // Show Edit Publication Window
        public void ShowEditWindow()
        {
            this.EditPublicationWindow.Show();
        }
    
        public void SavePublicationEdit(object sender, EventArgs e)
        {
        
        }
    
        // Fill Publication DDL
        public void fillPublicationTypeDropDown()
        {
            PublicationTypeBLL publicationTypeBLL = new PublicationTypeBLL();
            List<PublicationType> publicationTypeList = new List<PublicationType>();
            publicationTypeList = publicationTypeBLL.getAllPublicationTypes();
            StorePublicationType.DataSource = publicationTypeList;
            StorePublicationType.DataBind();
        }
    
        // Fill Sub-Publication DDL on Publication Change
        protected void fillSubPublicationTypeDropDown(String parentPublicationCode, String subPublicationTypeCode)
        {
            PublicationTypeBLL subPublicationTypeBLL = new PublicationTypeBLL();
            List<PublicationType> subPublicationTypeList = new List<PublicationType>();
            subPublicationTypeList = subPublicationTypeBLL.getSubPublicationTypes(parentPublicationCode);
    
            if (subPublicationTypeList != null)
            {
                hideAllPanels();
                StoreSubPublicationType.DataSource = subPublicationTypeList;
                StoreSubPublicationType.DataBind();
                this.ddlSubPublicationTypes.SelectedItem.Value = subPublicationTypeCode;
                getAttributes(subPublicationTypeCode);
            }
            else
            {
                divSubPublicationTypes.Hidden = true;
                getAttributes(parentPublicationCode);
            }
    
            ChangeLabels(parentPublicationCode);
        }
    
    public void fillDateDropDowns()
        {        
            //fill day drop down list
            for (int i = 1; i <= 31; i++)
            {
                ddlEndPublicationDays.Items.Add(new Coolite.Ext.Web.ListItem(i.ToString(), i.ToString()));
                ddlPublicationDays.Items.Add(new Coolite.Ext.Web.ListItem(i.ToString(), i.ToString()));
            }
    
            //fill year drop down list with current year and previous year (default to previous year)
            Coolite.Ext.Web.ListItem year = new Coolite.Ext.Web.ListItem();
            year.Text = (DateManager.GetCurrentYear() - 1).ToString();
            year.Value = (DateManager.GetCurrentYear() - 1).ToString();
    
            ddlPublicationYears.Items.Add(year);
            ddlEndPublicationYears.Items.Add(year);
    
            year.Text = DateManager.GetCurrentYear().ToString();
            year.Value = DateManager.GetCurrentYear().ToString();
    
            ddlPublicationYears.Items.Add(year);
            ddlEndPublicationYears.Items.Add(year);
    
            //ddlPublicationYears.SelectedItem.Value = (DateManager.GetCurrentYear() - 1).ToString();
        }
    Thank you!

Similar Threads

  1. [CLOSED] generating columns in a GridPanel
    By rnfigueira in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 11, 2011, 2:27 PM
  2. [CLOSED] Combobox: How to remove the duplicate items in the combobox?
    By csssi_coolite in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 09, 2011, 9:34 AM
  3. AjaxEvents on ToolbarButton generating errors
    By Patrick in forum 1.x Help
    Replies: 4
    Last Post: May 03, 2010, 5:51 AM
  4. [CLOSED] Generating TreeNodes in Codebehind
    By macap in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Mar 03, 2010, 5:22 AM
  5. Combobox Items bug ?
    By fabiomarcos in forum 1.x Help
    Replies: 3
    Last Post: Dec 26, 2008, 4:00 PM

Posting Permissions