如何将下拉列表的选定索引设置为从数据库中选择的值 [英] how to set the selected index of a dropdownlist to a value selected from database

查看:134
本文介绍了如何将下拉列表的选定索引设置为从数据库中选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!!!
我有一个下拉列表,其中有一个设置了DataValueField和DataTextField的sqldatasource.

现在我需要做的是选择一条记录进行编辑时,下拉列表现在应该显示该记录的值.

例如,如果数据库中的记录是"Australia",则下拉列表应显示"Australia"作为所选索引.

请告诉我该怎么做!

Hello!!!
I have a dropdownlist having a sqldatasource with DataValueField and DataTextField set.

Now what i need to do is when a record is selected for editing , dropdown list now should show the value that was there for that record.

for example if the record in the database was "Australia" then the dropdownlist should show "Australia" as selected index.

please tell me how to do this!!!

推荐答案

有一个selectedindex和selectedvalue属性.您可以设置它们.
There''s a selectedindex and a selectedvalue property. You can set those.


本文应为您提供帮助:
This article should help you out: MSDN: Walkthrough: Displaying a Drop-Down List While Editing in the GridView Web Server Control[^]


嗨 我以为您正在开发基于Windows的应用程序
多么容易上手
不要感到困惑,我想你可能已经知道了

dropdownlist click属性,您可以使用
之后,使用selecedvalue/selectedItem
获取选择的值 如果需要,可以获取selctedIndex值

然后准备您的数据库语句,并在其中包含条件以获取确切的详细信息.

那么您可能会知道该怎么做...
Hi I thought you are developing a Windows based app
what ever its so easy to start
don''t get confused I thought you might knew this already

dropdownlist click property you can use
after that fetch the selected value using selecedvalue/selectedItem
If you want you can fetch the selctedIndex value

then prepare your database statement and include where condition in it fetch the exact details.

then you might know what to do with it...


这篇关于如何将下拉列表的选定索引设置为从数据库中选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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