zoukankan      html  css  js  c++  java
  • 怎么取得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来回避这种情况

    风雪七月花溅墨
  • 相关阅读:
    JSON
    FBV & CBV
    django Tips
    Django2.2
    cookie & session
    ajax请求
    视图函数
    模板语法
    模板继承、组件
    python之路-----多线程与多进程
  • 原文地址:https://www.cnblogs.com/bobo41/p/3412467.html
Copyright © 2011-2022 走看看