/// <summary>
        /// 通用combox绑定
        /// </summary>
        /// <param name="cb"></param>
        /// <param name="dt"></param>
        /// <param name="strText"></param>
        /// <param name="strValue"></param>
        private void ComboDataBind( ComboBox cb,DataTable dt,string strText,string strValue)
        {
            if (0 < dt.Rows.Count)
            {
                cb.DisplayMember = strText;
                cb.ValueMember = strValue;
                cb.DataSource = dt.DefaultView;
                cb.SelectedIndex = 0;
            }
            
        }

  在form加载时上面的绑定是木有问题的,但是如果要两个combox关联着去绑定第二个,上面代码就会爆出“无法绑定到新的显示成员。 参数名: newDisplayMember”的错误,,,让我很是头疼+蛋碎,,,经历一番海查资料后,在回传的时候是要这样绑定的

private void PostBackComboDataBind(ComboBox cb, DataTable dt, string strText, string strValue)
        {
            if (0 < dt.Rows.Count)
            {
                cb.DataSource = dt.DefaultView;
                cb.DisplayMember = strText;
                cb.ValueMember = strValue;
                cb.SelectedIndex = 0;
            }
        }

 

相关文章:

  • 2021-10-31
  • 2021-07-20
  • 2021-08-14
  • 2022-03-06
  • 2021-06-27
  • 2021-08-21
  • 2022-12-23
猜你喜欢
  • 2021-11-28
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
相关资源
相似解决方案