显示selectedvalues文本名称 [英] Show selectedvalues text name

查看:67
本文介绍了显示selectedvalues文本名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

D TestCaseName

1 TestCycle1

2 TestCycle2

3 TestCycle3



这里我想选择ID,在插入数据库时​​我想显示TEXT即TestCycle1,我正在尝试这段代码。



我试过下面提到的我正在获取ID。



D TestCaseName
1 TestCycle1
2 TestCycle2
3 TestCycle3

Here i want to select the ID and while inserting in DB i want to show the TEXT i.e TestCycle1, I am trying this code.

I have tried the below mentioned code and in this i am getting the ID.

DefectManagement.TestCaseCycle_Value = Convert.ToInt32(ddlTestCycle.SelectedValue);





现在插入数据库时​​我想要那个ID的TEXT,如何在DB中插入选定的索引文本



我尝试了什么:



我试过下面提到的代码在这里我得到了ID。



DefectManagement.TestCaseCycle_Value = Convert.ToInt32(ddlTestCycle.SelectedValue);



Now while inserting in DB i want the TEXT of that ID, How can i insert selected index text in DB

What I have tried:

I have tried the below mentioned code and in this i am getting the ID.

DefectManagement.TestCaseCycle_Value = Convert.ToInt32(ddlTestCycle.SelectedValue);

推荐答案

您好,



在下拉列表中,您可以绑定2个值,例如 ID 名称



如果你想在UI中显示ID并选择你想要的ID,那么你应该将数据绑定到数据库然后你必须将ID绑定到文本字段和名称作为值字段。一旦绑定了两者,就可以使用以下属性访问这两个值。



1.)ddl.SelectedValue - >这将为您提供已绑定到下拉列表的文本字段。



2.)ddl.SelectedIndex - >将为您提供您在下拉列表中绑定的值字段。



使用您想要保存到DB的任何内容。



参考URL



谢谢,

Sisir Patro
Hi,

In the dropdownlist you can bind 2 values like ID and the Name.

If you want to show the ID in the UI and on select of that ID you want the value should go to the DB then you have to bind the ID to the text field and Name as value field. Once you have binded the both you can access the 2 values using the following properties.

1.) ddl.SelectedValue -> this will give you the Text field that you have binded to the dropdownlist.

2.) ddl.SelectedIndex -> will give you the value field that you have binded in the dropdownlist.

Use whatever you want to save to the DB accordingly.

Reference URL

Thanks,
Sisir Patro


这篇关于显示selectedvalues文本名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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