Example #1
0
        public static byte ListBindMultiKey(ListControl listBox,
                                            string sql,
                                            string[]    dataFieldKey,
                                            string dataFieldShow,
                                            string addZeroRow  = "",
                                            string selectValue = "",
                                            short selectIndex  = -888)
        {
            listBox.Items.Clear();

            try
            {
                if (PCIBusiness.Tools.NullToString(sql).Length < 5)
                {
                    return(22);
                }

                string dataValue;
                string keyValue;
                int    k;

                using (PCIBusiness.MiscList dList = new PCIBusiness.MiscList())
                    if (dList.ExecQuery(sql, 0) == 0)
                    {
                        while (!dList.EOF)
                        {
                            if (dataFieldKey.Length == 1)
                            {
                                keyValue = dList.GetColumn(dataFieldKey[0]);
                            }
                            else
                            {
                                keyValue = "";
                                for (k = 0; k < dataFieldKey.Length; k++)
                                {
                                    keyValue = keyValue + "/" + dList.GetColumn(dataFieldKey[k]);
                                }
                                if (keyValue.StartsWith("/"))
                                {
                                    keyValue = keyValue.Substring(1);
                                }
                            }
                            dataValue = dList.GetColumn(dataFieldShow);
                            listBox.Items.Add(new ListItem(dataValue, keyValue));
                            dList.NextRow();
                        }
                    }
                    else
                    {
                        return(5);
                    }

                if (addZeroRow.Length > 0)
                {
                    listBox.Items.Insert(0, (new ListItem(addZeroRow, "")));
                }

                if (listBox.Items.Count > 0)
                {
                    if (selectValue.Length > 0)
                    {
                        ListSelect(listBox, selectValue, "0");
                    }
                    else if (selectIndex >= listBox.Items.Count)
                    {
                        listBox.SelectedIndex = listBox.Items.Count - 1;
                    }
                    else if (selectIndex >= 0)
                    {
                        listBox.SelectedIndex = selectIndex;
                    }
                }
                return(0);
            }
            catch
            { }

            return(99);
        }
        public static void ListBind(ListControl listBox,
                                    string sql,
                                    object dataSource,
                                    string dataFieldKey,
                                    string dataFieldShow,
                                    string addZeroRow  = "",
                                    string selectValue = "",
                                    short selectIndex  = -888)
        {
            listBox.Items.Clear();

            try
            {
                if (PCIBusiness.Tools.NullToString(sql).Length > 0)
                {
                    string dataValue;
                    string keyValue;
                    using (PCIBusiness.MiscList dList = new PCIBusiness.MiscList())
                        if (dList.ExecQuery(sql, 0) == 0)
                        {
                            while (!dList.EOF)
                            {
                                dataValue = dList.GetColumn(dataFieldShow);
                                keyValue  = dList.GetColumn(dataFieldKey);
                                listBox.Items.Add(new ListItem(dataValue, keyValue));
                                dList.NextRow();
                            }
                        }
                }
                else if (dataSource != null)
                {
                    listBox.DataSource     = dataSource;
                    listBox.DataValueField = dataFieldKey;
                    listBox.DataTextField  = dataFieldShow;
                    listBox.DataBind();
                }
                else
                {
                    return;
                }

                if (addZeroRow.Length > 0)
                {
                    listBox.Items.Insert(0, (new ListItem(addZeroRow, "0")));
                }

                if (listBox.Items.Count > 0)
                {
                    if (selectValue.Length > 0)
                    {
                        ListSelect(listBox, selectValue, "0");
                    }
                    //	else if ( selectIndex == 0 )
                    //		listBox.SelectedIndex = 0;
                    else if (selectIndex >= listBox.Items.Count)
                    {
                        listBox.SelectedIndex = listBox.Items.Count - 1;
                    }
                    else if (selectIndex >= 0)
                    {
                        listBox.SelectedIndex = selectIndex;
                    }
                }
            }
            catch (Exception ex)
            { }
        }