Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used Checkboxlist with textbox popupcontolis for multi selection dropdownlist and selected items text displayed in the text box.which is work in google chrome...but does not work in firefox....selected item does not displayed in text box in firefox..

Here is my coding

Multicheckcombo.ascx

XML
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MultiCheckCombo.ascx.cs" Inherits="Mobius.D2K.Web.Administration.Modules.MultiCheckCombo" %>


<script type = "text/javascript">
    //Script para incluir en el ComboBox1 cada item chekeado del chkListMateriales
    function CheckItem(checkBoxList) {


        var options = checkBoxList.getElementsByTagName('input');
        var arrayOfCheckBoxLabels = checkBoxList.getElementsByTagName('label');
        var s = "";

        for (i = 0; i < options.length; i++) {
            var opt = options[i];

            if (opt.checked) {

                s = s + ", '" + arrayOfCheckBoxLabels[i].innerText.replace("'", "''") + "'";

            }
        }
        if (s.length > 0) {
            s = s.substring(2, s.length); //sacar la primer 'coma'
        }

        var TxtBox = document.getElementById("<%=txtCombo.ClientID%>");
        TxtBox.value = s;
        document.getElementById('<%=hidVal.ClientID %>').value = s;
    }
</script>



<asp:TextBox ID="txtCombo" runat="server" ReadOnly="True" Width="200"
    Font-Size="Large" ForeColor="#660033"></asp:TextBox>
<ajaxToolkit:PopupControlExtender ID="PopupControlExtender111" runat="server"
    TargetControlID="txtCombo" PopupControlID="Panel111" Position="Bottom" >
</ajaxToolkit:PopupControlExtender>

<input type="hidden" name="hidVal" id="hidVal" runat="server" />

<asp:Panel ID="Panel111" runat="server" style="vertical-align:top;" ScrollBars="Vertical" Width="250" Height="150" BackColor="AliceBlue" BorderColor="Gray" BorderWidth="1">

    <asp:CheckBoxList ID="chkList" AutoPostBack ="true"
        runat="server"
        Height="150" onclick="CheckItem(this)">
    </asp:CheckBoxList>

</asp:Panel>






Multicheckcombo.ascx.cs



C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Odbc;
using Mobius.D2K.Common.Utils;
using Mobius.D2K.Common.Utils.Html;
using System.Data.SqlClient;

namespace Mobius.D2K.Web.Administration.Modules
{
    public partial class MultiCheckCombo : BaseMobiusAdministrationUserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }

         /// <summary>


        ///Set the Width of the CheckBoxList

        /// </summary>

        public int WidthCheckListBox
        {
            set
            {
                chkList.Width = value;
                Panel111.Width = value + 20;
            }
        }
        /// <summary>
        /// Set the Width of the Combo
        /// </summary>
        public int Width
        {
            set { txtCombo.Width = value; }
            get { return (Int32)txtCombo.Width.Value; }
        }
        public bool Enabled
        {
            set { txtCombo.Enabled =  value; }
        }
        /// <summary>
        /// Set the CheckBoxList font Size
        /// </summary>
        public FontUnit fontSizeCheckBoxList
        {
            set { chkList.Font.Size = value; }
            get { return chkList.Font.Size; }
        }
        /// <summary>
        /// Set the ComboBox font Size
        /// </summary>
        public FontUnit fontSizeTextBox
        {
            set { txtCombo.Font.Size = value; }
        }



        /// <summary>
        /// Add Items to the CheckBoxList.
        /// </summary>
        /// <param name="array">ArrayList to be added to the CheckBoxList</param>
        public void AddItems(ArrayList array)
        {
            for (int i = 0; i < array.Count; i++)
            {
                if (array[i].ToString().Trim() != string.Empty)
                {
                    chkList.Items.Add(array[i].ToString());
                }
            }
        }


        /// <summary>
        /// Add Items to the CheckBoxList
        /// </summary>
        /// <param name="dr"></param>
        /// <param name="nombreCampoTexto">Field Name of the OdbcDataReader to Show in the CheckBoxList</param>
        /// <param name="nombreCampoValor">Value Field of the OdbcDataReader to be added to each Field Name (it can be the same string of the textField)</param>
        //public void AddItems(OdbcDataReader dr, string textField, string valueField)
        //{
        //    ClearAll();
        //    int i = 0;
        //    while (dr.Read())
        //    {
        //        chkList.Items.Add(dr[textField].ToString());
        //        chkList.Items[i].Value = i.ToString();
        //        i++;
        //    }
        //}
        public void AddItems(SqlCommand myCommand, string textField, string valueField)
        {
            ClearAll();
            //int i = 0;
            //while (dr.Read())
            //{
            //    chkList.Items.Add(dr[textField].ToString());
            //    chkList.Items[i].Value = i.ToString();
            //    i++;
            //}
            chkList.DataSource = myCommand.ExecuteReader();
            chkList.DataTextField = valueField;
            chkList.DataValueField = textField;
            chkList.DataBind();
        }


        /// <summary>
        /// Uncheck of the Items of the CheckBox
        /// </summary>
        public void unselectAllItems()
        {
            for (int i = 0; i < chkList.Items.Count; i++)
            {
                chkList.Items[i].Selected = false;
            }
        }

        /// <summary>
        /// Delete all the Items of the CheckBox;
        /// </summary>
        public void ClearAll()
        {
            txtCombo.Text = "";
            chkList.Items.Clear();
        }

        /// <summary>
        /// Get or Set the Text shown in the Combo
        /// </summary>
        public string Text
        {
            get { return hidVal.Value; }
            set { txtCombo.Text = value; }
        }
    }
}




Pls give me a good solution


Thanks in advance...
Posted
Updated 5-Sep-12 19:49pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900