DropDownList 如何绑定 键值对

lixianrong890611 2011-04-25 09:58:07

DropDownList1.DataTextField=??
DropDownList1.DataValueField= ??

??处 该如何绑定键值对的值?
...全文
164 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixianrong890611 2011-04-25
  • 打赏
  • 举报
回复

DropDownList1.DataTextField="key";
DropDownList1.DataValueField= "value";



正确答案!
冷雪液 2011-04-25
  • 打赏
  • 举报
回复
/// <summary>
/// 绑定比例下拉列表
/// </summary>
private void LoadZoom()
{
Dictionary<int, string> ites = new Dictionary<int, string>();
ites.Add(0, "100%");
ites.Add(1, "75%");
ites.Add(2, "50%");
ites.Add(3, "25%");
ites.Add(4, "10%");
for (int i = 0; i < ites.Count; i++)
{
tsbtnZoom.Items.Add(ites[i].ToString());
}
tsbtnZoom.SelectedIndex = 0; //默认为100%
}
lanqiang456 2011-04-25
  • 打赏
  • 举报
回复
DropDownList1..DataTextField="";//数据库中选择出的字段,要显示的文本;
DropDownList1.DataValueField="";//数据库中选择出的字段,该项的值;

先要前面为下拉列表指定数据来源```
紫川秀 2011-04-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 qq346127416 的回复:]
DropDownList1.DataSource = 你的数据集
DropDownList1.DataTextField=显示的列
DropDownList1.DataValueField= 取得值的列
[/Quote]
楼上的答案都是对的.
cjh200102 2011-04-25
  • 打赏
  • 举报
回复
楼上说的很全面。
Value就是键 Text是值

[Quote=引用 1 楼 xiangjing163 的回复:]

DataTextField 是窗体显示的值
DataValueField 是窗体存储的值

比如: 省市区的绑定 省 的 中文 湖南 需要DataTextField 去绑定sql 字段的文本值

湖南对应的ID值 比如112 DataValueField 去绑定sql 字段的值
[/Quote]
qq346127416 2011-04-25
  • 打赏
  • 举报
回复
DropDownList1.DataSource = 你的数据集
DropDownList1.DataTextField=显示的列
DropDownList1.DataValueField= 取得值的列


njltf 2011-04-25
  • 打赏
  • 举报
回复
DropDownList1.DataSource=List<>;
DropDownList1..DataTextField="";//数据库中选择出的字段,要显示的文本;
DropDownList1.DataValueField="";//数据库中选择出的字段,该项的值;
wtj2832 2011-04-25
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
DataTextField 是窗体显示的值
DataValueField 是窗体存储的值

比如: 省市区的绑定 省 的 中文 湖南 需要DataTextField 去绑定sql 字段的文本值

湖南对应的ID值 比如112 DataValueField 去绑定sql 字段的值


110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧