Asp.net下拉列表DataValuefield和datatextfields [英] Asp.net Drop Down List DataValuefield and datatextfields
本文介绍了Asp.net下拉列表DataValuefield和datatextfields的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的页面上有一个DropDownList控件,
我将同时绑定DataValueField和DataTextFiled.
例如:员工详细信息,
数据值字段= 1
数据文本字段="ABCD"
我希望dropdownlist中的文本显示如下
"1-ABCD"
我也想从此下拉列表中选择数据值字段"
上面的示例中多数民众赞成在1
我该怎么做
请帮助
I have a DropDownList Control in my page,
i am binding both DataValueField and DataTextFiled to it.
For example: Employee details,
Data value Field =1
Data Text Field ="ABCD"
i want the text in dropdownlist will show like this
"1-ABCD"
and also i want to select the Data Value Field from this dropdownlist
thats 1 in above example
How can i do this
Please help
推荐答案
希望您会找到答案
合并要在下拉列表中显示的两个字段
Hope you will find the answer
Concatenate Two Fields to Display in Dropdown List
要么创建一个自定义对象,要么从查询本身获取文本字段值为"1-ABCD".
目前,您似乎是一个初学者,请尝试使用Query方法.提取数据时,请串联ID和Text字段,然后在绑定时将此字段用作datatextfield.
样本:
Either create a custom object or get the textfield value as ''1 - ABCD'' from query itself.
For now, it looks like you are a beginner, try the Query way. When fetching the data, concatenate the ID and Text field and then use this field as the datatextfield while binding.
Sample:
SELECT
ID, TextF, (ID + '-' + TextF) AS IDTEXTF
FROM
MyTable
mydropdown.Datasource = myFetchedDataTable;
mydropdown.DataValueField = "ID";
mydropdown.DataTextField = "IDTEXTF";
mydropdown.Databind();
这篇关于Asp.net下拉列表DataValuefield和datatextfields的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文