触发所选索引上的服务器事件已更改 [英] Fire a server event on selected index changed

查看:79
本文介绍了触发所选索引上的服务器事件已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的asp.net/c#网站创建一个下拉列表编辑/搜索框,代码现在工作正常,但我希望当所选索引被更改时它会触发一个事件



这是我现在的代码

I am creating a dropdown edit/search box for my asp.net/c# website, the code now works fine but I want that when the selected index gets changed it would fire an event

This is the code I have got now

<form  runat="server" id="form1">
        <div class="ui-widget">
            <asp:DropDownList ID="combobox" runat="server" AutoPostBack="true">
                <asp:ListItem Value="White" Selected="True">White</asp:ListItem>
                <asp:ListItem Value="Black">Black</asp:ListItem>
                <asp:ListItem Value="Blue">Blue</asp:ListItem>
            </asp:DropDownList>
        </div>
    </form>





我尝试了多种方法来实现这一点,其中一项就是添加这个:



I have tried multiple things to get this working, one of it is adding this:

OnSelectedIndexChanged="combobox_SelectedIndexChanged1"





事件根本不会触发但有时只有在点击Enter后才会触发,我需要它才能触发索引改变了。

我不知道我是做错了还是没有办法......

有些人可以帮我找一个解决方案

谢谢,



编辑:

我添加了EnableViewState,我不确定这是做什么的,但是在我休息之后我可以清楚地看到,当我点击下拉列表中的另一个项目时,它不会触发事件,因为它不会进入这个onSelectedIndexChanged代码块。我很困惑为什么这不起作用



The event does not fire at all but sometimes only after hitting Enter, I need it to fire when the index gets changed.
I don't know if I am doing this wrong or if there just isn't a way..
Can some please help me to find a solution
Thank You,


I added the EnableViewState, I am not sure what that is meant to do, but after putting my break point.. i can clearly see that when I click on another item from the drop downlist it doesn't fire the event because it doesn't go into this onSelectedIndexChanged code block.. I am so confused to why this is not working

推荐答案

从你的标记中我发现它缺少这个事件:

Well from your markup I see it is lacking the event:
<asp:dropdownlist id="combobox" runat="server" autopostback="true" enableviewstate="true" onselectedindexchanged="combobox_SelectedIndexChanged" xmlns:asp="#unknown">
   <asp:listitem value="White" selected="True">White</asp:listitem>
   <asp:listitem value="Black">Black</asp:listitem>
   <asp:listitem value="Blue">Blue</asp:listitem>
</asp:dropdownlist>



在您的代码中:


In your code behind:

protected void combobox_SelectedIndexChanged(object sender, EventArgs e)
{
   //Do stuff
}





这应该有效。



祝你好运,

OI



This should work.

Good luck,
OI


把所选索引上的一些断点改为代码并查看它是否正在编译......
put Some break points on selected index changed code and see whether it is compiling or not ...


这篇关于触发所选索引上的服务器事件已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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