怎么取得dropdownlist选中的ID值
把数据库绑定在dropdownlist中,然后把选中的dropdownlist的项的ID值保存在另外的一个数据库中.怎么取得dropdownlist选中的ID值呢??
this.DropDownList1.Items.Clear();
this.DropDownList1.DataSource = wwddt;
this.DropDownList1.DataTextField = "version_name";
this.DropDownList1.DataValueField = "version_id";
this.DropDownList1.DataBind();
因为显示的是"version_name"这个字段,我现在是想当选中"version_name"字段的项时,把"version_name"字段对应的"version_id"值存入另外的一个数据库中.
答案:
string a = dropdownlist.SelectedText;//获取选中的text
string b = dropdownlist.SelectedValue; //获取选中的value
int c = dropdownlist.SelectedIndex; //获取选中的索引
如果你的dropdownlist.datasource是在pageload里面绑定的话
很有可能是由于不断的初始化(不断的执行dropdownlist.datasource)导致每回都取道的默认值
一般用ispostback来回避这种情况
怎么取得dropdownlist选中的ID值的更多相关文章
- jquery设置checkbox状态,设置dropdownlist选中值,隐藏某控件,给某控件追加东西
jquery设置checkbox状态 $("[ID$=chkType]").attr("checked", true); jquery设置dropdownlis ...
- Javascript获取select下拉框选中的的值
现在有一id=test的下拉框,怎么拿到选中的那个值呢? 分别使用javascript原生的方法和jquery方法 <select id="test" name=" ...
- C# mvc DropDownList选中状态无效情况分析
情况: DropDownList控件使用List<SelectListItem>()设置下拉选项和默认值.当控件的Name和后台的ViewBag(或ViewData)的Key重复,会导致选 ...
- Jquery获取select,dropdownlist,checkbox下拉列表框的值
jQuery获取 Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); ...
- JavaScript- 获得TreeView CheckBox里选中项的值
获得TreeView CheckBox里选中项的值,对JSDOM控制还不是很熟,感觉不太容易.试了很多次终于成功了. 代码如下 <body> <form id="form1 ...
- jQuery获取radio选中项的值【转藏】
<title></title> <script src="js/jquery-1.7.2.min.js"></script> < ...
- js获取下拉列表(select)选中项的值和文本
获取下拉列表选中项的值和文本(select) <html> <head> <meta charset="utf-8"/> <title&g ...
- jquery实现全选、全不选、反选、获取选中的所有值总结
HTML 我们的页面上有一个歌曲列表,列出多行歌曲名称,并匹配复选框供用户选择,并且在列表下方有一排操作按钮. <!doctype html> <html> <head& ...
- easyui-combotree选中指定的值
选中根节点: //station_id为combotree控件id var station = $('#station_id').combotree('tree').tree('getRoots'); ...
随机推荐
- linux下编译gcc6.2.0
linux下编译gcc6.2.0 在archlinx的下gcc已经更新到6.2.1了,win10的WSL下还是gcc4.8.官方源没有比较新的版本,于是自己编译使用. GCC6的几个新特性 GCC 6 ...
- bzoj4237 稻草人
我是萌萌的传送门 题意不难理解吧-- 一开始看到这道题的时候lrd告诉我这题要分治,还给我讲了讲分治要怎么写,好像是CDQ+树状数组来着--(好吧我已经忘了--)然而我第一眼看完题之后的思路是数据结构 ...
- hosts 屏蔽百度
127.0.0.1 localhost cpro.baidu.com vie.baidu.com cpro.baidu.com ubmcmm.baidustatic.com uumcmm.ba ...
- Winform自定义控件基础(一)
1.设置图像和文字以抗锯齿的方式呈现 g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHin ...
- Code First 迁移,及迁移错误
迁移错误: 今天在使用EF6 Code First时,出现如下错误,折腾了老半天.分享一下,帮后面的兄弟少走弯路. PM> Enable-Migrations Checking if the c ...
- C# Mvc异常处理过滤器
using System; using System.Text; using EMS.Domains.Core; using System.Web.Mvc; using Json.Net; using ...
- 第一天--html
<!Doctype html><html> <head> <meta charset="UTF-8"> ...
- android adb 命令详解
ADB (Android Debug Bridge) 是android SDK中的工具,需要先配置环境变量才能使用.起调试桥的作用,可以管理安卓设备.(也叫debug工具) ---------查看设 ...
- Oracle中使用REGEXP_SUBSTR,regexp_replace函数
REGEXP_SUBSTR函数格式如下: function REGEXP_SUBSTR(String, pattern, position, occurrence, modifier)__srcstr ...
- sh5.while 脚本练习
脚本编程: 顺序结构 选择结构 if, case 循环结构 for,while,until while循环:适用于循环次数未知的场景 语法: while CONDITION;do statement ...