用下拉列表绑定两列数据集

用下拉列表绑定两列数据集

本文介绍了使用下拉列表绑定两列数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想用下拉列表绑定两列数据集。可能吗?如果有,那请帮助我。怎么样?这是我在这个论坛上的第一个问题。我很高兴通过这个论坛找到你的帮助。

Hi,
I want to bind two columns of dataset with a dropdownlist. Is It possible? If yes, then Please help me.How? This is my first question on this forum. It will be pleasure for me to find help by you through this forum.

推荐答案



protected void FillDrpEmpInfo()
   {
       dtTemp = new DataTable();
       dtTemp = CreateEmpDataTable();
       dtTemp.Columns.Add("Displaly", typeof(string), "ID + ' - ' + Name + ' ' + Surname");

       this.drpEmpInfo.DataSource = dtTemp;
       this.drpEmpInfo.DataTextField = "Displaly";
       this.drpEmpInfo.DataValueField = "ID";
       this.drpEmpInfo.DataBind();
   }

   public DataTable CreateEmpDataTable()
   {
       //Initialize DataTable
       dt = new DataTable();

       //Create columns in DataTable
       dt.Columns.Add("ID");
       dt.Columns.Add("Name");
       dt.Columns.Add("Surname");
       dt.Columns.Add("Salary");
       dt.Columns.Add("Designation");

       //Create Rows in DataTable
       dt.Rows.Add("1", "KiranKumar", "Roy", "5500", "Web Developer");
       dt.Rows.Add("2", "Hetvi", "Roy", "4500", "Web Developer");
       dt.Rows.Add("3", "Shankar", "Shetty", "7500", "Support Engg");
       dt.Rows.Add("4", "Loe", "Louis", "6500", "Support Engg");
       dt.Rows.Add("5", "Sanaj", "Meppery", "8000", "Sales Executive");
       dt.Rows.Add("6", "Jubair", "Mohd", "7000", "DNN Developer");
       dt.Rows.Add("7", "Sanjay", "Nadher", "5000", "CA");
       dt.Rows.Add("8", "Jyoti", "Ramwani", "3000", "Receptionist");
       dt.Rows.Add("9", "Sajid", "Shahid", "10000", "Sales and Techanical Manager");
       dt.Rows.Add("10", "Vijay", "Roy", "10000", "Glass Artist");

       return dt;
   }


这篇关于使用下拉列表绑定两列数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:37