DropDownList绑定没有TextField和ValueField [英] DropDownList Binding without TextField and ValueField

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

问题描述

任何人都可以告诉我,如果我不想传递DataTextField和DataValueField,我如何将DropDownList与数据源绑定?

目前我正在为所有项目绑定Value as System.Data.DataRowView 。



如果有人知道解决方案,请告诉我。



先谢谢。



感谢你们的建议,



但我有一个场景,我为用户提供选项以获得Dropdownlist数据通过SQL查询。

很明显,我限制用户获取两个以上的列数据,但如何从用户输入的查询中获取哪一个是DataTextField和DataValueField?

我刚刚使用Dropdown DataSource属性绑定DataSet,因为我可能不知道RunTime中的列名。



如果您有任何建议,请帮助我。



再次感谢您的回复。

Can anyone Tell me if I do not want to pass DataTextField and DataValueField how can I bind DropDownList with datasource ?
At present I am getting bound Value as System.Data.DataRowView for all the Items.

Please Tell me If anyone knows the Solution.

Thanks in Advance.

Thanks Guys for your suggestions,

But I have a scenario where I am providing option to the User to get Dropdownlist data through SQL Query.
Obiviously, I am restricting user for fetching more than Two column data but How do I get which one is DataTextField and DataValueField from user entered query ?
I have just Bound the DataSet with Dropdowns DataSource Property as I may not be knowing the column names in RunTime.

Please Help Me Out If you have suggestions.

Thanks again for your replies.

推荐答案

其实如果我们没有设置datatextfield和datavaluefield然后dropdownlist无法理解你要显示的列,因为数据有两列以上所以我们指定了列名
Actually if we not set datatextfield and datavaluefield then dropdownlist not able to understand whihch column you want to show because data have more than two columns so we have specify the column names






要显示要绑定的值,dropdownlist需要datatextfield,dropdownlist无法为此绑定整个表,您需要选择gridview。
Hi,

To show the value you want to bind dropdownlist need datatextfield,dropdownlist can not bind a whole table for this you need to choose gridview.


If你没有告诉你的控制你想要用于显示的特定属性,它只是对它绑定的项目调用 ToString(),并将其用于显示。对于大多数对象,默认情况下 ToString()只返回类型名称。因此,对于下拉列表,您必须设置 DataValueField DataTextField



--Amit
If you don''t tell your control what specific properties you want to use for display, it just calls ToString() on the items it binds to, and uses that for display. Which for most objects, ToString() by default just returns the type name. So, for dropdownlist you must set DataValueField and DataTextField.

--Amit


这篇关于DropDownList绑定没有TextField和ValueField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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