怎样获取dropdowmlist里面字段对应的id

作者&投稿:闾新 (若有异议请与网页底部的电邮联系)
如何获取选中的dropdownlist的项对应绑定数据的id(主键)~

C# 在WEB 开发时,有一个Page_Load事件,在这个事件中写数据绑定事件。
procted void Page_Load(object sender ,EventArgs e)
{
if(!IsPostBack){
.....
DropDownList1.DataSource= tb //DrowDownList1 表示下拉框的些tb 表示从数据库取回数据
// 这里假设有tb 中有 FieldID 也 FieldText 字段。
DropDownList1.DataValueField = "FieldID";
DropDownList1.DataTextField = "FieldText";

DropDownList1.DataBind();


}



用另一个方法取值

private int GetDropDownSelectedID(){
int rInt= 0;
rInt = DropDownList1.SelectedItem=!null? (int)DropDownList1.SelectedValue: rInt;
return rInt;
}


调用以上方法即可。

string a = dropdownlist.SelectedText;//获取选中的text
string b = dropdownlist.SelectedValue; //获取选中的value
int c = dropdownlist.SelectedIndex; //获取选中的索引
如果你的dropdownlist.datasource是在pageload里面绑定的话
很有可能是由于不断的初始化(不断的执行dropdownlist.datasource)导致每回都取道的默认值
一般用ispostback来回避这种情况

比如说,你设置dropdownlist数据源时,,this.控件名.DataValueField="id";
取值时:int id = this.控件名.SelectValue;或int id = this.控件名.selectItem.value;


asp.net利用NamingContainer属性获取GridView行号的方法
在最近的一个项目中,用到在GridView模板列中添加有DropDownList控件,并开启其AutoPostback属性。当发生SelectedIndexChanged事件时,想同时获取其所在的行号,从而获取相应的行信息。由于DropDoweList与button不同,无法指定其CommandName,所以,也就没办法通过常规的方法捕获所在行的索引。颇费了些周折,后来找到...

怎样将一个界面中DropDownList中的全部数据传到另一个界面的DropDownList...
1.用viewstate或session存储一个数组变量,两个用法相似;2.既然两个控件数据一样,如果又要用到多个页面,何不存入数据库,然后绑定到列;3.用户控件,自定义一个.ascx页面。

英语好的朋友来帮帮忙(我是做了的,但不知对不对,所以还请回答者保证80%...
二 Do not do Show wait drop do doing Give Be put listening 三 on out after at behind between beside 四 Please do not do that.This book is not for me.What are you going to do?Is he shaving now?I am working hard at school.He will turn on the radio.五 I plan to giv...

Css样式中哪些标签最常用?
recordNumber 获取数据集中生成对象的原始记录。scopeName 获取为该元素定义的命名空间。scrollHeight 获取对象的滚动高度。scrollLeft 设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离。scrollTop 设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离。scrollWidth 获取对象的滚动宽度。sourceIndex ...

cctv5火箭记录片的那首英文歌叫什么名字
And do your jiggy mama til the break of dawn Load the rocket, shock it and rock it til you drop Do the bump to the bump and don't stop END 第二首:西城男孩的《Seasons in the sun》歌手:Westlife 专辑:Westlife Goodbye to you, my trusted friend,we've known each other...

Ricky Martin的《Loaded》 歌词
Load the rocket, shock it and rock it til you drop Do the bump to the bump and don't stop Do you remember how we were Do you remember summer days Sometimes I feel like going down Walk like a loaded man (down down)Get the bump to the bump de bump de bump soul (down...

Primal Scream的《Loaded》 歌词
Load the rocket, shock it and rock it til you drop Do the bump to the bump and don't stop Do you remember how we were Do you remember summer days Sometimes I feel like going down Walk like a loaded man (down down)Get the bump to the bump de bump de bump soul (down...

sister 7的《Loaded》 歌词
Load the rocket, shock it and rock it til you drop Do the bump to the bump and don't stop Do you remember how we were Do you remember summer days Sometimes I feel like going down Walk like a loaded man (down down)Get the bump to the bump de bump de bump soul (down...

La 25的《Dame Mas》 歌词
Load the rocket, shock it and rock it til you drop Do the bump to the bump and don't stop Do you remember how we were Do you remember summer days Sometimes I feel like going down Walk like a loaded man (down down)Get the bump to the bump de bump de bump soul (down...

中央5台,赛后播放火箭集锦时的背景音乐的名字。
And do your jiggy mama til the break of dawn Load the rocket, shock it and rock it til you drop Do the bump to the bump and don't stop END 第二首:西城男孩的《Seasons in the sun》歌手:Westlife 专辑:Westlife Goodbye to you, my trusted friend,we've known each other ...

柯坪县19866785701: vb.net dropdowmlist 如何绑定数据表中的某一列 -
公畅复方: comboBox.DataSource =数据表; comboBox.DisplayMember=foodsetName;

柯坪县19866785701: 请问如何将后台数据库查询的值设定在前台dropdowmlist? -
公畅复方: 展开全部$(document).ready(function () { BindDropDownList(); });//绑定数据 function BindDropDownList() { $.getJSON("test.ashx?deptid=" + deptid, null, function (json) { $.each(json, function (i) { $("#userid").append($("").val(...

柯坪县19866785701: 如何用 jquery 获取button里的name值. -
公畅复方: 可以用jquery的attr函数获取button里面的name值.1、新建html文档,在body标签中添加input标签,标签类型为button,为这个标签设置一个id,然后引入jquery文件:2、获取之前设置id的input标签,代码的格式是$('#id名'),这时之前设置id的input标签就会被选中:3、为选中的标签添加attr函数,函数的参数为name,这时button里面的name值就被获取到了:

柯坪县19866785701: 怎样获取DropDownList绑定的记录值,怎么获得的总是第一个记录? -
公畅复方: 用 DropDownList.SelectedValue 绝对可以.可能是你在选择下拉列表时候回传了,DropDownList 又重新绑定了一次.所以每次都只能获得第一个记录,你试试在页面加载的时候判断下是否是回传. 例: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // DropDownList 绑定. } }

柯坪县19866785701: 如何获取win10系统蓝屏dump日志文件 -
公畅复方: 1、dump日志文件的存放目录位于:其默认路径是Windows文件夹下的Minidump文件夹(C:windowsminidump); 2、如果你在windows文件夹中没有发现minidump文件夹,那么可能是你的win10没有设置导致. 设置方法: 1、右键点击“此电脑”属性,然后点击“高级系统设置”; 2、点击系统启动,系统故障和调试信息下的设置按钮; 3、然后勾选“将事件写入系统日志” 及设置储存等选项,如下图: 4、通过设置后,再出现蓝屏等故障的时候,我们就可以在C:windowsminidump文件夹找到dump文件了!

柯坪县19866785701: 在js中怎样获取table里面选中的行号 -
公畅复方: <html><br><head><br><script type="text/javascript" src="jquery-1.5.2.min.js"><br></script><br><script type="text/javascript"><br> $(document).ready(function(){<br> $("#mytable tr").click(function(){<br> $("#mytable tr").removeAttr("...

柯坪县19866785701: 怎样获取WIFI侠密码查看器的ROOT -
公畅复方: 尊敬的用户您好: 未经ROOT的手机查看连接过的wifi密码的方法如下: 1、打开手机,进入手机桌面后,找到手机设置,点击进入手机的设置界面. 2、进入后找到系统安全和隐私的选项,点击进入. 3、进入后点击系统备份,新建一个备份文...

柯坪县19866785701: MYSQL中如何获取最后一条记录 -
公畅复方: 先在主表中插入记录,然后获得自动生成的id,以它为基础插入从表的记录. 这里面有个困难,就是插入主表记录后,如何获得它对应的id. 通常的做法,是通过“select max(id) from tablename”的做法,但是显然这种做法需要考虑并发的情况,需要在事务中对主表加以“X锁“,待获得max(id)的值以后,再解锁.

柯坪县19866785701: 在 html 中 如何获取 INPUT 里面VALUE的值 -
公畅复方: js原生的代码获取.可以给你的input取一个id 然后用 document.getElementById('').value;获取value值要使用jq 就可以给input取一个class或者id 然后用$('.class名').val() 或者$('#id名').val();获取

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网