将值和文本动态绑定到DropDownlist [英] Dynamic binding of value and text to a DropDownlist

查看:77
本文介绍了将值和文本动态绑定到DropDownlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我发现当我将行绑定到Arraylist的dropdownlist时,"value"和"text"都分配了相同的值.

我不想要这个,有没有办法相应地绑定值?

请帮助我,谢谢!!

Hi,

I found that when I bind rows to a dropdownlist from an Arraylist both the ''value'' and ''text'' were assigned to the same value.

I don''t want this, is there a way to bind the values accordingly?

Please help me,Thank you!!

推荐答案

希望它能起作用.....
dropdownlist1.datavaluefield.text
dopdownlist1.datatextfield.text
hope it works.....
dropdownlist1.datavaluefield.text
dopdownlist1.datatextfield.text


填充数据表中的数据.然后将此数据表保留到DropDownList.
Fill the the data''s in DataTable. Then assisgn this DataTable to the DropDownList.
ddl.DataSource = dataTable
ddl.DataValueField = "value field name"
ddl.DataTextField = "textfield name"
dd.DataBind()


OleDbConnection con = new OleDbConnection(connection);
                DataSet ds = new DataSet();
                OleDbDataAdapter ad = new OleDbDataAdapter("select Tittle from smsstorage order by Tittle Asc", con);
                ad.Fill(ds);
                //ddlsmsstorage.Items.Clear();
                ddlsmsstorage.Items.Add("---Select---");


                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ddlsmsstorage.Items.Add(ds.Tables[0].Rows[i][0].ToString());

               
                   
                }


这样我们也可以添加您想要的字段..........


like this also we can add which field you want.............


这篇关于将值和文本动态绑定到DropDownlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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