473,626 Members | 3,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList - SelectedIndexCh anged doesn't fire

Hi guys,

I'm trying to learn ASP.NET and got a problem with DroDownList...
SelectedIndexCh anged doesn't fire.
Maybe you'll be able to suggest something.

I think it may be connected with the fact I fill this list dynamically.

I use the following code:

--presentation--
<%@ Page Language="C#" MasterPageFile= "~/Site.master"
AutoEventWireup ="true" CodeFile="index .aspx.cs"
Inherits="Pagin gAndSorting_ind ex" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHol derID="MainCont ent"
Runat="Server">
<br />
<asp:Label ID="PageInfo" runat="server"
Text="Label"></asp:Label>&nbsp ;<asp:DropDownL ist ID="PageList"
runat="server" AutoPostBack="T rue"
OnSelectedIndex Changed="PageLi st_SelectedInde xChanged">
</asp:DropDownLis t><br />
<br />
<asp:GridView ID="Products" runat="server"
AutoGenerateCol umns="False" DataKeyNames="P roductID"
DataSourceID="O bjectDataSource 1" AllowPaging="Tr ue"
OnDataBound="Pr oducts_DataBoun d">
<Columns>
<asp:BoundFie ld DataField="Prod uctName" HeaderText="Pro duct
Name" SortExpression= "ProductNam e" />
<asp:BoundFie ld DataField="Cate goryName"
HeaderText="Cat egory" ReadOnly="True" SortExpression= "CategoryNa me" />
<asp:BoundFie ld DataField="Supp lierName"
HeaderText="Sup plier" ReadOnly="True" SortExpression= "SupplierNa me" />
<asp:BoundFie ld DataField="Unit Price" HeaderText="Pri ce"
SortExpression= "UnitPrice" />
<asp:CheckBoxFi eld DataField="Disc ontinued"
HeaderText="Dis continued" SortExpression= "Discontinu ed" />
</Columns>
</asp:GridView>
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
OldValuesParame terFormatString ="original_{ 0}"
SelectMethod="G etProducts"
TypeName="Produ ctsBLL"></asp:ObjectDataS ource>
</asp:Content>
---------------

-----logic----
using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

public partial class PagingAndSortin g_index : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
}

protected void Products_DataBo und(object sender, EventArgs e)
{
PageInfo.Text = string.Format(" Page {0}/{1}",
Products.PageIn dex + 1, Products.PageCo unt);

PageList.Items. Clear();

for (int i = 0; i < Products.PageCo unt; i++)
{
ListItem pageListItem = new ListItem(string .Concat("Go to
page: ", i + 1), i.ToString());
PageList.Items. Add(pageListIte m);

if (i == Products.PageIn dex)
pageListItem.Se lected = true;
}
}

protected void PageList_Select edIndexChanged( object sender,
EventArgs e)
{
Products.PageIn dex = Convert.ToInt32 (PageList.Selec tedValue);
}
}
---------------

--
Thanks in advance
Damien

Jan 26 '07 #1
7 12060
"Damien" <no************ **@recursor.net wrote in message
news:11******** **************@ m58g2000cwm.goo glegroups.com.. .
I'm trying to learn ASP.NET and got a problem with DroDownList...
SelectedIndexCh anged doesn't fire.
Maybe you'll be able to suggest something.

I think it may be connected with the fact I fill this list dynamically.
Hmm - well, you specify AutoEventWireup ="true" in your Page directive, and
you have set the AutoPostBack property of the DropDownList control to
"true", so it can't be either of those...
protected void PageList_Select edIndexChanged( object sender, EventArgs e)
{
Products.PageIn dex = Convert.ToInt32 (PageList.Selec tedValue);
}
}
Are you absolutely certain the event isn't firing...? E.g. if you put a
breakpoint in the above code, does it jump into it...?

When you drop the DropDownList control and select a different option, does
the screen "flash" is if it's posting back...?
Jan 26 '07 #2
Are you absolutely certain the event isn't firing...? E.g. if you put a breakpoint in the above code, does it jump into it...?

I'm sure. I put breakpoint inside the event but it is never reached.
When you drop the DropDownList control and select a different option, does the screen "flash" is if it's posting back...?
Yes, the screen "flash", so page is posting back.

Another strange thing is when I add another dropdownlist to the form,
then add a few items to it... its SelectedIndexCh anged event fires no
matter which dropdownlist I use to select value.

The same event for both DDL... how is it possible?

Jan 26 '07 #3
"Damien" <no************ **@recursor.net wrote in message
news:11******** *************@q 2g2000cwa.googl egroups.com...
>Are you absolutely certain the event isn't firing...? E.g. if you put a
breakpoint in the above code, does it jump into it...?

I'm sure. I put breakpoint inside the event but it is never reached.
Hmm - OK...
>When you drop the DropDownList control and select a different option,
does the screen "flash" is if it's posting back...?

Yes, the screen "flash", so page is posting back.
Well that's a start, at least... :-)
Another strange thing is when I add another dropdownlist to the form,
then add a few items to it... its SelectedIndexCh anged event fires no
matter which dropdownlist I use to select value.
Ah yes, now this is a particularly irritating bug...

The only way I've found of working round this is to wrap the entire code
inside the DropDownList's SelectedIndexCh anged event with this:

if (Request.Form["__EVENTTAR GET"] == PageList.Unique ID)
{
// rest of code goes here
}

The event still fires in response to postbacks from other controls, but none
of its code will run unless the actual DropDownList itself initiated the
postback...

I'm actually quite pleased that you're experiencing this (if you see what I
mean!), because Microsoft Technical Support as well as a couple of the MVPs
in here flatly refuse to acknowledge that this bug exists...
Jan 26 '07 #4
Thank for the clue (good one).
I will try this. However I think there is something wrong with the
following code:

--
//clear out all of the items
PageList.Items. Clear();

for (int i = 0; i < Products.PageCo unt; i++)
{
ListItem pageListItem = new ListItem(string .Concat("Page ", i + 1),
i.ToString());
PageList.Items. Add(pageListIte m);

if (i == Products.PageIn dex) pageListItem.Se lected = true;
}
--

If I add DDL items in VS environment, everything works fine.

Maybe, if I find out what is wrong with the above fragment, the event
problem will solve automatically.
MS products amaze me all the time, you know :)

--
Thanks a lot
Damien

Jan 26 '07 #5
"Damien" <no************ **@recursor.net wrote in message
news:11******** *************@v 33g2000cwv.goog legroups.com...
However I think there is something wrong with the following code:
Like what...?
--
//clear out all of the items
PageList.Items. Clear();

for (int i = 0; i < Products.PageCo unt; i++)
{
ListItem pageListItem = new ListItem(string .Concat("Page ", i + 1),
i.ToString());
PageList.Items. Add(pageListIte m);

if (i == Products.PageIn dex) pageListItem.Se lected = true;
}
--
The only thing I might have done differently would be to evaluate whether
the item should be selected *before* adding it to the Items collection, e.g.

if (i == Products.PageIn dex) pageListItem.Se lected = true;
PageList.Items. Add(pageListIte m);
Jan 26 '07 #6
>However I think there is something wrong with the following code:
>Like what...?
No idea. But all works just fine when I create all items by hand.
Maybe I should place this code within different event. I'll work on
this.
>--
//clear out all of the items
PageList.Items .Clear();
for (int i = 0; i < Products.PageCo unt; i++)
{
ListItem pageListItem = new ListItem(string .Concat("Page ", i + 1),
i.ToString() );
PageList.Items. Add(pageListIte m);
> if (i == Products.PageIn dex) pageListItem.Se lected = true;
}
--
The only thing I might have done differently would be to evaluate whether
the item should be selected *before* adding it to the Items collection, e.g.

if (i == Products.PageIn dex) pageListItem.Se lected = true;
PageList.Items. Add(pageListIte m);
Any particular reason why?

Jan 26 '07 #7
"Damien" <no************ **@recursor.net wrote in message
news:11******** *************@k 78g2000cwa.goog legroups.com...
>The only thing I might have done differently would be to evaluate whether
the item should be selected *before* adding it to the Items collection,
e.g.

if (i == Products.PageIn dex) pageListItem.Se lected = true;
PageList.Items .Add(pageListIt em);

Any particular reason why?
Force of habit, really...

1) Instantiate the object
2) Populate its properties
3) Add it to the collection
Jan 26 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3117
by: genc ymeri | last post by:
Hi, I have a C# from and I'm trying to add some code in onKeyDown event. But it doesn't fire at all............ Any idea ? Thanks a lot.
3
1500
by: Brent Burkart | last post by:
I have a dropdownlist that won't fire .The autopostback is set to true and I do a ispostback check before population the ddl. Can anyone help please? Brent
2
3051
by: Paul Lacey | last post by:
When dynamically placing dropdownlists inside a panel, the dropdownlist's SelectedIndexChanged event doesn't fire. If you take the dropdownlist out of the panel it works properly. Autopostback is set to True on the DropDownList. Is there something I'm missing? Any help would be greatly appreciated.
1
2909
by: Timo | last post by:
I am trying to use the DropDownList_SelectedIndexChanged event on a dropdown which is dynamically populated with different values at runtime, depending on what the user has been doing. The dropdown works and the event fires except when the user selects the *first* item in the list, which appears to be the default selection, even though the generated HTML code does not have a "selected" property set. Is it possible to cause the...
1
5731
by: Jack | last post by:
Hello, I have a dropdown list on a user control and the AutoPostBack property is set to True. I want to use the SelectedIndexChanged event to populate some text boxes based on what the user chose in the dropdown list. However, the SelectedIndexChanged event doesn't fire. In the immediate window it appears that the index is not changing when I select a different option in the list.
6
2203
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
45
4705
by: Pat | last post by:
its seems asp.net validation doesn't fire when using FireFox? Tested a page and it doesn't fire. It seems the javascript doesn't fire Any ideas?
3
22433
by: amanbindal | last post by:
How to fire Dropdownlist selectedindexchanged event in JAVASCRIPT? Actually i want that on Dropdownlist selectedindexchanged event i got displayed data from a XML file.....!!
0
8266
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.