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

问题描述:



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

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.

dropdownlist.DataSource = ds.Tables [0];

dropdownlist.DataTextField =datacolumnname;

dropdownlist.DataValueField =idfield;

dropdownlist.DataBind();
dropdownlist.DataSource = ds.Tables[0];
dropdownlist.DataTextField = "datacolumnname";
dropdownlist.DataValueField = "idfield";
dropdownlist.DataBind();


你的意思是Datagrid?

然后看看使用DataGrid中的DropDownList进行多项选择



数据集是一个代码对象,我没有看到显示下拉列表的任何意义。
Do you mean Datagrid?
Then see Multiple selection using DropDownList in DataGrid.

A dataset is a code object and I don't see any point in showing a dropdownlist in that.


试试这个一个。

try this one.
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;
   }