常见值的下拉问题 [英] Dropdown problem with common values

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

问题描述

嗨我有一个数据源的下拉列表,如

empname dept

-----------------

Rahul 02

martin 01

sachin 02



我把这个表绑定了到我的下拉列表,当我尝试访问dept中的下拉选择事件更改每次我只得到Rahul。即使我选择了萨钦。



问题是什么?我假设我的数据值字段(02和02)中有两个常见值这是一个问题吗?



谢谢

Suresh

Hi I've a dropdown list with datasource like
empname dept
-----------------
Rahul 02
martin 01
sachin 02

i've binded this table to my dropdown list and when i try to access dept in dropdown selected event change everytime I'm gettin Rahul only. even i selected sachin.

Whats the problem? What I assume is I've two common values in my datavalue field (02 and 02) is this a problem?

Thank you
Suresh

推荐答案

在不分析代码的情况下,解决问题几乎是不可能的,因为我们无法读懂你的想法

但要绑定一个下拉你需要

Without analysing your code it is almost impossible to solve your problem as we can't read your mind
but to bind a drop down you need
DataSource,DataTextField,DataValueField
something like 
        ddlABC.Items.Add(new ListItem("--Please Select--", "0"));
        ddlABC.DataSource = <a list="" or="" datasource="">;
        ddlABC.DataTextField = "SomeName";
        ddlABC.DataValueField = "SomeID";
        ddlABC.DataBind();


ddl.Datasource = yourtablename(datatable);

ddl.DataTextField = tablecolumn name;

ddl.DataBind();
ddl.Datasource=yourtablename(datatable);
ddl.DataTextField="tablecolumn name";
ddl.DataBind();


这意味着在每次回发时,您的下拉列表都会被重新加入。将您的DropDownList绑定在Page_Load事件的 Not IsPostBack 块中。试试这样:

This means that on each postback your dropdown is getting rebinded. Bind your DropDownList in Not IsPostBack block of your Page_Load event. Try like this:
if(!IsPostBack){
    DropDownList1.DataSource = YourDataSource;
    DropDownList1.DataTextField = "EmpName";
    DropDownList1.DataValueField = "Dept";
    DropDownList1.DataBind();
}





- Amit


这篇关于常见值的下拉问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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