selectedValue、selectedItem、selectedItem.value区别
最新推荐文章于 2024-09-03 17:14:20 发布
飞扬时间
最新推荐文章于 2024-09-03 17:14:20 发布
阅读量1w
收藏
14
点赞数
4
分类专栏:
ASP.NET
文章标签:
selectedItem.value
selectedValue
selectedItem
ASP.NET
专栏收录该内容
30 篇文章
订阅专栏
public virtual ListItem SelectedItem { get { int selectedIndex = this.SelectedIndex; if (selectedIndex >= 0) { return this.Items[selectedIndex]; } return null; } } public virtual string SelectedValue { get { int selectedIndex =
this.SelectedIndex; if (selectedIndex >= 0) { return this.Items[selectedIndex].Value; } return string.Empty; } }
在没有选定任何项的情况下,SelectedValue默认值是string.Empty,而SelectedItem默认值是null(也就是说通过SelectedItem.Value可能发生异常)
1. selectedIndex——指的是dropdownlist中选项的索引,为int,从0开始,可读可写
2. selectedItem——指的是选中的dropdownlist中选项,为ListItem,只读不写
3. selectedValue——指的是选中的dropdownlist中选项的值,为string, 只读不写
4. selectedItem.Text——指的是选中的dropdownlist中选项的文本内容,与selectedItems的值一样为string,可读可写
5. selectedItem.value——指的是选中的dropdownlist中选项的值,与selectedValue的值一样,为string,可读可写
光看文字可能不太理解,我也是通过程序来加深理解的,下面举个例子:
前台代码:
代码
1 view plaincopy to clipboardprint?
2 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="dropdown.aspx.cs" Inherits="dropdown" %>
3
4
5
6
7
8
9
10
11
30
31
后台代码:
代码
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12 public partial class dropdown : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16
17 }
18 protected void Button1_Click(object sender, EventArgs e)
19 {
20 Label1.Text = "selectedIndex=" + DropDownList1.SelectedIndex;
21 Label2.Text = "selectedItem=" + DropDownList1.SelectedItem;
22 Label3.Text = "selectedValue=" + DropDownList1.SelectedValue;
23 Label4.Text = "selectedItem.text=" + DropDownList1.SelectedItem.Text;
24 Label5.Text = "selectedItem.value=" + DropDownList1.SelectedItem.Value;
25 }
26 }
确定要放弃本次机会?
福利倒计时
:
:
立减 ¥
普通VIP年卡可用
立即使用
飞扬时间
关注
关注
4
点赞
踩
14
收藏
觉得还不错?
一键收藏
知道了
1
评论
分享
复制链接
分享到 QQ
分享到新浪微博
扫一扫
举报
举报
专栏目录
SelectedValue与SelectedItem.Value的区别
weixin_34007906的博客
10-11
844
public virtual ListItem SelectedItem {
get {
int selectedIndex = this.SelectedIndex;
if (selectedIndex >= 0) {
return this.Items[selectedIndex];
}
...
【wpf】wpf 中 SelectedValue 和 SelectedItem 的区别和关联
songhuangong123的博客
08-13
1442
SelectedItem用于获取或设置整个选定项的对象。
SelectedValue在没有设置 `SelectedValuePath` 时,会与 `SelectedItem` 返回相同的对象;但一旦设置了 `SelectedValuePath`,`SelectedValue` 返回的将是由 `SelectedValuePath` 指定的属性的值,而不是整个对象。
1 条评论
您还未登录,请先
登录
后发表或查看评论
ListBox等控件的SelectedItem,SelectedValue,SelectedValuePath属性详解
weixin_42253874的博客
09-03
1370
初学WPF可能会对诸如ComboBox、ListBox等集合控件的当前选择项的绑定有所疑惑,控件提供了两个可绑定对象:SelectedItem\SelectedValue,同时还有DisplayMemberPath\SelectedValuePath。本节来讲述一下它们的设计意图和用法。
关于selecteditem.value和selecteditem.text
weixin_30270561的博客
07-05
382
当从数据库中读取的数据绑定到dropdownlist时,只能用selecteitem.text再将这些数据取出来,因为数据库绑定到dropdownlist的过程中,只绑定了text,而没有绑定value。
转载于:https://www.cnblogs.com/qdhjbym/archive/2011/07/05/2098235.html...
dropdownlist控件的几个属性selectedIndex、selectedItem、selectedValue、selectedItem.Text、selectedItem.value的区别
ba_wang_mao的专栏
08-19
4267
1. selectedIndex——指的是dropdownlist中选项的索引,为int,从0开始,可读可写
2. selectedItem——指的是选中的dropdownlist中选项,为ListItem,只读不写
3. selectedValue——指的是选中的dropdownlist中选项的值,为string, 只读不写
4. selectedItem.Text——指的是选中的dropdownlist中选项的文本内容,与selectedItems的值一样为string,可读可写
5. sel.
private bool DoAdd()
{
bool result = false;
ld.core.bll.Dtry _nsystems = new ld.core.bll.Dtry();
ld.core.model.Dtry nsystem = new ld.core.model.Dtry();
nsystem.title = this.title.SelectedItem.Text;
nsystem.typeid = this.title.SelectedItem.Value;
nsystem.DepNum = Convert.ToInt32(this.DepName.SelectedItem.Value);
nsystem.DepName = this.DepName.SelectedItem.Text;
nsystem.user_nickname = this.user_nickname.SelectedItem.Text;
nsystem.usernum = this.user_nickname.SelectedValue;
nsystem.CreateMan = loginuser.nick_name;
if (loginuser.user_name == "admin")
{
nsystem.Creator = 1;
}
else
nsystem.Creator = Convert.ToInt32(loginuser.user_name);
result = _nsystems.Add(nsystem) > 0;
return result;
}
03-29
好的,我需要帮助用户审查和调试他们的C#方法private bool DoAdd()。首先,用户没有提供具体的代码,所以可能需要询问更多细节。但根据他们提供的引用内容,可能涉及异步编程、线程安全或WebBrowser控件相关的问题。...
private bool DoAdd()
{
bool result = false;
ld.core.bll.Dtry _nsystems = new ld.core.bll.Dtry();
ld.core.model.Dtry nsystem = new ld.core.model.Dtry();
if((this.typename.Value is null)||(this.typename.Value ==""))
{
return false;
}
else
{
var t = this.typename.Value;
nsystem.typename = t;//权限的id集合
nsystem.typeid = this.typeid.ToString();
nsystem.CreateMan = loginuser.user_name;
nsystem.Creator = loginuser.lineid;
nsystem.user_nickname = this.user_nickname.SelectedItem.Text;
nsystem.usernum = this.user_nickname.SelectedValue;
result = _nsystems.Add(nsystem) > 0;
}
return result;
}
03-19
nsystem.usernum = this.user_nickname.SelectedValue; // 下拉框实际值 ``` 5. **执行添加操作** ```csharp result = _nsystems.Add(nsystem) > 0; ``` - 调用业务逻辑层的 `Add` 方法插入数据 - 通过...
{{ selectedLabel || placeholder }}
▼
const model = defineModel()
const selectedLabel = ref('')
const selectOptions = ref([])
const isOpen = ref(false)
const props = defineProps({
placeholder: {
type: String,
default: '请选择'
},
options: {
type: Array,
default: []
},
//top
rules: {
type: Array,
default: () => []
}
})
// top
const addChildClect = inject('addChildClect');
function validateItem() {
debugger
for (let rule of props.rules) {
// 必填校验
if (rule.required && !model.value) {
errorMessage.value = rule.message || '请输入内容';
checkBool.value = true;
return true; // 校验失败
}
checkBool.value = false;
return false; // 校验成功
}
}
// blur 事件触发校验
function handleBlur() {
const blurRules = props.rules.filter(rule => rule.trigger === 'blur');
if (blurRules.length > 0) {
validateItem();
}
}
// change/input 事件触发校验
function handleChange() {
const changeRules = props.rules.filter(rule => rule.trigger === 'change');
if (changeRules.length > 0) {
validateItem();
}
}
// top
const emit = defineEmits(['change'])
function handleClick(item) {
model.value = item.value
toggleMenu()
}
function setOtherOptionDefault(value) {
selectOptions.value.forEach(item => {
if (item.value != value) {
item.selected = false
} else {
item.selected = true
}
})
}
function toggleMenu() {
isOpen.value = !isOpen.value
}
provide('pushOptions', item => {
selectOptions.value.push(item)
})
watch(
() => model, // 监听的属性
(newVal, oldVal) => { // 变化时的回调函数
if (newVal != null && newVal != undefined && newVal.value != null && newVal.value != undefined) {
selectOptions.value.forEach(item => {
if (item.value == newVal.value) {
selectedLabel.value = item.label
setOtherOptionDefault(newVal.value)
}
})
} else {
selectedLabel.value = ""
}
},
{ deep: true }
);
onMounted(() => {
if (props.options.length > 0) {
selectOptions.value = props.options
}
selectOptions.value.forEach(item => {
if (item.value == model.value) {
selectedLabel.value = item.label
setOtherOptionDefault(model.value)
}
})
// top
if (addChildClect) {
addChildClect({ validate: validateItem });
}
})
.option {
width: 100%;
padding: 3px 0px 3px 0px;
&:hover {
background-color: #fa0808;
}
span {
margin-left: 15px;
font-size: 14px;
user-select: none;
}
}
.selected {
color: #409eff;
}
.select {
position: relative;
width: 200px;
}
.trigger {
width: 100%;
padding: 8px 12px;
border: 1px solid #ccc;
background-color: #fff;
text-align: left;
cursor: pointer;
}
.arrow {
float: right;
transition: transform 0.3s ease;
}
.arrow.rotated {
transform: rotate(180deg);
}
.menu {
position: absolute;
top: 100%;
left: 0;
width: calc(100% - 1px);
height: 0px;
overflow-x: auto !important;
overflow-y: auto !important;
border: 1px solid #ccc;
border-top: none;
background: white;
z-index: 10;
transition: height 0.3s ease;
&::-webkit-scrollbar {
width: 5px;
/* 垂直滚动条宽度 */
height: 5px;
/* 水平滚动条高度(可选) */
}
/* 滚动条滑块部分 */
&::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.3);
border-radius: 4px;
}
/* 滚动条轨道 */
&::-webkit-scrollbar-track {
background-color: #f1f1f1;
}
}
.menu.menu_open {
height: 100px !important;
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.2s;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
当我没选择的时候想打出信息
最新发布
07-18
根据提供的Vue组件代码,我注意到你想要在用户没有选择任何选项时显示一条错误... const selectedItem = selectOptions.value.find(item => item.value === model.value); if (selectedItem) { selectedLabel.value =...
根据 numericUpDown1.Value和 numericUpDown2.Value值,再结合 comboBox1向dataGridView1添加数据
03-15
用户需要获取当前选中的项,可以通过SelectedItem或SelectedValue属性来获取。如果ComboBox的数据源是一个列表,可能需要处理其选中的值,并转换为字符串或其他类型,添加到数据行中。 现在,数据如何添加到...
dropdownlist控件的几个属性selectedIndex、selectedItem、selectedValue、selectedItem.Text、selectedItem.value的区别...
weixin_30484247的博客
08-13
402
1. selectedIndex——指的是dropdownlist中选项的索引,为int,从0开始,可读可写
2. selectedItem——指的是选中的dropdownlist中选项,为ListItem,只读不写
3. selectedValue——指的是选中的dropdownlist中选项的值,为string, 只读不写
4. selectedItem.Text——指的是选中的drop...
服务器控件的几个属性 SelectedIndex、SelectedItem、SelectedValue、SelectedItem.Text、selectedItem.value...
weixin_30693183的博客
04-12
491
转自http://blog.csdn.net/iqv520/article/details/4419186
1. SelectedIndex ——选项的索引,为int,从0开始,可读可写
2. SelectedItem ——选择项,是一个对象,为ListItem,只读不写
3. SelectedValue —— 选项的值,为string, 只读不写
4. SelectedItem.Text...
转载:ListBox的SelectedValue和SelectedItem的区别
weixin_30784141的博客
10-20
676
转载:ListBox的SelectedValue和SelectedItem的区别
原文:http://www.beacosta.com/blog/?p=9
What is the difference between SelectedValue and SelectedItem?
When they are used by themselv...
C/C++/C#问题记录(二)获取ComboBox中SelectedItem的值
MoYummy的专栏
04-30
7358
用到过两种方法方法一:((ComboBoxItem)combo.SelectedItem).Content.ToString();方法二:int index = combo.SelectedIndex;
string label = combo.Items.GetItemAt(index).ToString();
Qt文档阅读笔记-Qt工作笔记-QTableWidget::selectedItems()官方解析与实例(如何进行多选)
IT1995的博客
01-23
1万+
目录
前言
官方解析
博主例子
前言
QTableWidget::selectedItems():
在使用QTableWidget中,可以选中多行,如何从界面获取多行的数据,可以使用selectedItems()进行操作!
官方解析
返回被选择的item的链表。
这个函数返回鼠标选中项的链表,如果有空白的Item,可以使用selectedIndexes()函数。
...
PyQt(Python+Qt)学习随笔:QListWidget获取当前选中项的selectedItems方法
老猿Python
02-08
9244
老猿Python博文目录
专栏:使用PyQt开发图形界面Python应用
老猿Python博客地址
QListWidget的selectedItems方法返回列表部件中所有选中项的一个列表,调用语法如下:
list selectedItems()
返回列表中的每个元素就是一个QListWidgetItem对象,如果没有选中项,则返回空列表。
老猿Python,跟老猿学Python!
老...
WPF Datagrid.SelectedItem的用法实践
热门推荐
silentrock的专栏
10-29
1万+
WCF+WPF的一个项目,有两个模块,一个是xiao
有关SelectedValue,SelectedItem,Text
HelloLWei的专栏
12-02
2005
public partial class Form1 : Form
{
DataTable dtblTemp;
public Form1()
{
InitializeComponent();
InitialTable();
FillComboBox();