如何绑定下拉列表 [英] How to bind dropdown list

查看:99
本文介绍了如何绑定下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 DataTable dtCurrentTable = new DataTable
for (int i = 0; i < dtCurrentTable.Rows.Count; i++)
 {
    DropDownList ddltype =
    (DropDownList)gvFormula.Rows[rowIndex].Cells[1].FindControl("ddltype");


     ddlproduct.SelectedItem.Text = dtCurrentTable.Rows[i]["ddltype"].ToString();
     rowIndex++;
 }





当我分配下拉列表值时。它只显示一个值。

我的要求是在选择时绑定下拉列表中的所有值



When I assign dropdown list value . Its showing only one value.
My requirement is to bind all the values in dropdown list when selected

推荐答案

DataSet ds = new DataSet();
     SqlDataAdapter da = new SqlDataAdapter("Select distinct(name)from employee", connection);
     da.Fill(ds);
     drpemployee.DataSource = ds;
     drpemployee.DataValueField = "name";
     drpemployee.DataBind();
     drpemployee.Items.Insert(0, "--Select--");


访问这里..





如何绑定下拉列表 [ ^ ]



或< br $> b $ b

如何根据Asp.net C#中的第一个或另一个下拉列表将数据绑定或填充到下拉列表中[ ^ ]
visit here..


how to bind dropdownlist[^]

or

How to bind or populate data into a Dropdown List based on first or another Dropdown List in Asp.net C#[^]


试试希望它能运作:

try it hope it will work:
DropDownList ddltype =
    (DropDownList)gvFormula.Rows[rowIndex].Cells[1].FindControl("ddltype");
       DataTable dtCurrentTable = new DataTable
for (int i = 0; i < dtCurrentTable.Rows.Count; i++)
 {
ddlproduct.Items.Insert(i,new ListItem( dtCurrentTable.Rows[i]["product"].ToString(), dtCurrentTable.Rows[i]["product"].ToString()));



}


}


这篇关于如何绑定下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆