下拉列表Asp.net C# [英] Dropdownlist Asp.net C#

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

问题描述

HI,
我在名为viewpage的网页之一中使用Dropdownlist,它在其中显示数据库.我的问题是,当我声明dropdownlist.items.clear();时,每当我单击下拉列表中的项目时,它不会填充选定的项目,而是仅填充我的数据库"的第一条记录".我有6个表格,该表格应显示在视图页中.

当我删除dropdownlist.item.clear();时,它会显示选中的项目,但在下拉列表中,它会增加dropdownlist中出现的项目

请帮助
谢谢您,


I am using Dropdownlist in one of web page called viewpage where it displays database. My Question is that when i declare dropdownlist.items.clear(); then whenever i click on items of dropdownlist, it does not populate selected item but populates only 1st Record of My database. I have 6 table which should be shown in viewpage.

And when i remove dropdownlist.item.clear(); then it shows selected item but in dropdown it increment items which are present in dropdownlist

Please Help
Thank you,

推荐答案

然后,每当我单击下拉列表中的项目时,它不会填充选定的项目,而是仅填充我的数据库的第一条记录
听起来您的下拉列表在更改事件上正在重新填充.一个简单的调试应该可以帮助您.

根据您所说的,这听起来像是您在重新绑定上失去了选择,这很正常.

只需将下拉绑定的代码放在IsPostback页面属性中即可.删除行dropdownlist.item.clear();

就像这样:
then whenever i click on items of dropdownlist it does not populate selected item but populates only 1st Record of My database
Sounds like your dropdown is getting re-populate on change event. A simple DEBUG should help you out.

Based on what you say, it sounds like, you are loosing your selection on re-binding which is normal.

Just put the code of dropdown binding in IsPostback page property. Remove the line dropdownlist.item.clear();

So something like:
if(!IsPostback)
{
  //Populate dropdown
}


if(!IsPostback)
{ 
 //Populate dropdownlist
}



它将解决您的问题.



It will solve your problem.


这篇关于下拉列表Asp.net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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