本文介绍了如何填写所有项目按升序排列的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 通过使用以下代码,我填写所有组合框。但这些物品不是我的订单。我怎样才能按照升级顺序设置所有物品。 var customer = new Customer() ; customer.FirstName = - 选择客户 - ; customerList.Insert(0,customer); var customerddl = customerList.Select(custo => new Customer { CustomerCode = custo.CustomerCode, FirstName = custo.FirstName ++ custo .LastName })。ToList(); ddlCustomers.DataSource = customerddl; ddlCustomers.DataTextField =FirstName; ddlCustomers.DataValueField =CustomerCode; ddlCustomers.DataBind(); 解决方案 试试这个 DataTable Dt = new DataTable(); //保存所有数据以显示在组合框 Dt中.Columns.Add( ID); Dt.Columns.Add(姓名); Dt.Rows.Add(0,Stephan); Dt.Rows.Add(1,Antony); Dt.Rows.Add(2,Mike); Dt.DefaultView.Sort =Name ASC; //这将按升序转换你的记录 combobox1.DataSource = Dt; combobox1.DisplayMember =姓名; combobox1.ValueMember =Id; By using following code I fill all the combo-box. But the items are not ia a order.How I can I set all the items in acending order.var customer = new Customer(); customer.FirstName = "--Select Customer--"; customerList.Insert(0, customer); var customerddl = customerList.Select(custo => new Customer { CustomerCode = custo.CustomerCode, FirstName = custo.FirstName + " " + custo.LastName }).ToList(); ddlCustomers.DataSource = customerddl; ddlCustomers.DataTextField = "FirstName"; ddlCustomers.DataValueField = "CustomerCode"; ddlCustomers.DataBind(); 解决方案 这篇关于如何填写所有项目按升序排列的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 03:43