dropDownList selectedIndex总是返回0 [英] dropDownList selectedIndex return 0 always

查看:95
本文介绍了dropDownList selectedIndex总是返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello everyone,



页面结构

页面 - >放置持有人 - >网络用户控制 - >下拉列表



这是我的页面元素。有一个click事件来生成新的webUserControl并将它放到PlaceHolder上。

现在我的问题是

我在webUserControl里面有三个Dropdownlist

和dropdownlist的所有值都从xml文件填充。



这里有一些图片来澄清我的问题

所有都在WebUserControl中,它将动态创建关于Click事件的发生



1)假设这是我的第一个下拉列表 - > i)DropdownlList



2)现在假设我从dropdownlist1中选择了动词选项,其他dropdownlist2将可见并根据dropdownlist1选项填充其中的项目





3)**现在主要问题从这里开始,**
当我点击辅助选项时
,我应该得到辅助文本的索引。它是3.但它总是返回索引0



这个dropDownList不保持所选的值。



请提出解决此问题的建议。

感谢您

解决方案

问题是您填写的是表格中的第1个下拉列表加载和每次发生某些事件时它会加载表单我猜你没有保留更新面板所以它再次填充你的第一个下拉菜单并导致所选索引更改事件触发,这使得你的dropdown2选择索引0一次又一次。





所以我的建议是你继续填写你的第一个下拉,因为下面的表格负载



 如果(!IsPostback)则
// 在此处填写您的下拉菜单
end if

< br $> b $ b



i猜它可以帮助你

使用



如果不是IsPostBack然后



''这里做你的下拉数据绑定工作





结束如果


非常感谢所有人。

Raj先生你是绝对正确的。控制在每个页面加载事件上刷新。

甚至我在我的web使用控件中应用了更新面板但没有用。



巴布先生先生,很抱歉,但这对我的控制无效。



我已经解决了我的问题。



实际上,正如我所说的那样,我在点击事件发生时创建动态控件并放置到位置。

和占位符清除每个回发,然后再次加载web用户控件。由于这个dropdownlist2依赖于dropdownlist1得到刷新并清除所有值。



解决方案:

写入OnInit()方法并在该调用中用于填写dropdownlist1的值。

Postback cant反映在dropdownlist1上。



工作正常。



感谢先生


Hello Everyone,

Page Structure
Page -> Place Holder -> web User control -> Dropdownlists

This is my Page Elements. There is click event to generate new webUserControl and place it onto PlaceHolder.
Now my Problem is that
I have three Dropdownlist inside webUserControl
and all values of dropdownlist populates from xml files.

Here is some Images to clarify my Problem
"All are inside WebUserControl which will created dynamically on the occurance of Click event"

1) suppose this is my first Drop down list -> i) DropdownlList

2) Now suppose I am selected "verb" option from dropdownlist1 automatically other dropdownlist2 will be visible and populates items in it according to dropdownlist1 selection


3) **Now main Problem starts here, **
when I am clicked on "Auxiliary" option, I am supposed to get index of Auxiliary text. It is 3. but it always returns index 0

this dropDownList does not hold the selected value.

Please give suggesions to resolve this problem.
Thanking you

解决方案

The problem is you are filling your 1st drop-down list in form load and every time some event happens it loads the form i guess u have not kept update panel so again it fills your first drop down and causes selected index changed event to fire which makes your dropdown2 selected index 0 again and again.


so my suggestion is you keep filling of your first drop down as following in form load

if(!IsPostback) then
//fill your drop-down 1 here
end if




i guess it helps you


use

If Not IsPostBack Then

'' here do u dropdown data bind work


End If


Thank you so much to all.
Mr. Raj Sir You are absolutely right. controls getting refresh on each page load event.
even I applied update panel in my web use control but no use.

Mr. Babu Sir, Sorry but It will not work for my control.

I have solved my problem.

Actually , as I said I am creating my dynamic control in the occurrence of click event and placed in place holder.
and placeholder clears on each postback and then again load then web User Control. Due to this dropdownlist2 which dependent on dropdownlist1 gets refresh and cleared all values.

Solution :
write OnInit () method and inside that call function for filling up the values of dropdownlist1.
Postback cant reflects on dropdownlist1.

It works fine.

thanking you sir


这篇关于dropDownList selectedIndex总是返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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