473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

DropDownList - SelectedIndexChanged

Hello there
I was trying to find something about this on web but with no success.
I am using code behind.
Basically I am creating drop down list dynamically.
Everything works but calling SelectedIndexChanged event never fires up.
I found some discussions regarding this problem, but couldn't find
answer....
Here is my code.

Protected WithEvents ddl As System.Web.UI.WebControls.DropDownList
For z = 0 To dg.Items.Count - 1
ddl = New System.Web.UI.WebControls.DropDownList
ddl.Style("width") = "150"
ddl.ID = z.ToString

ddl.DataSource = dstCust
ddl.DataTextField = "cust_name"
ddl.DataValueField = "cust_id"
ddl.DataBind()
ddl.Attributes.Add("onchange", "return
(ddl_SelectedIndexChanged(New Object, New System.EventArgs));")
dg.Items(z).Cells(1).Controls.Add(ddl)
Next

Private Sub ddl_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddl.SelectedIndexChanged
Dim x As String = "This function is never called!!!!!!!"
End Sub

Apr 27 '06 #1
9 3800
Adding the attribute will make the method to be called on the client side --
that is not what you want.
Remove this line
ddl.Attributes.Add("onchange", "return(ddl_SelectedIndexChanged(New Object,
New System.EventArgs));")

Add a handler for the ddl instead
AddHandler ddl.SelectedIndexChanged, AddressOf ddl_SelectedIndexChanged

and then set the AutoPostBack property of the ddl to true.
ddl.AutoPostBack = True

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
<j_****@hotmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
Hello there
I was trying to find something about this on web but with no success.
I am using code behind.
Basically I am creating drop down list dynamically.
Everything works but calling SelectedIndexChanged event never fires up.
I found some discussions regarding this problem, but couldn't find
answer....
Here is my code.

Protected WithEvents ddl As System.Web.UI.WebControls.DropDownList
For z = 0 To dg.Items.Count - 1
ddl = New System.Web.UI.WebControls.DropDownList
ddl.Style("width") = "150"
ddl.ID = z.ToString

ddl.DataSource = dstCust
ddl.DataTextField = "cust_name"
ddl.DataValueField = "cust_id"
ddl.DataBind()
ddl.Attributes.Add("onchange", "return
(ddl_SelectedIndexChanged(New Object, New System.EventArgs));")
dg.Items(z).Cells(1).Controls.Add(ddl)
Next

Private Sub ddl_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddl.SelectedIndexChanged
Dim x As String = "This function is never called!!!!!!!"
End Sub

Apr 27 '06 #2
Thanks for response.
Unfortunatelly it's not working...
Here is my code again

Protected WithEvents ddl As System.Web.UI.WebControls.DropDownList
For z = 0 To dg.Items.Count - 1
ddl = New System.Web.UI.WebControls.DropDownList
ddl.Style("width") = "150"
ddl.ID = z.ToString

ddl.DataSource = dstCust
ddl.DataTextField = "cust_name"
ddl.DataValueField = "cust_id"
ddl.DataBind()
AddHandler ddl.SelectedIndexChanged, AddressOf
ddl_SelectedIndexChanged
ddl.AutoPostBack = True
Next

Private Sub ddl_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddl.SelectedIndexChanged
Dim x As String = "This function is never called!!!!!!!"
End Sub

Apr 27 '06 #3
Is the form having a post back? Do you have any code in the Page load event
?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
<j_****@hotmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
Thanks for response.
Unfortunatelly it's not working...
Here is my code again

Protected WithEvents ddl As System.Web.UI.WebControls.DropDownList
For z = 0 To dg.Items.Count - 1
ddl = New System.Web.UI.WebControls.DropDownList
ddl.Style("width") = "150"
ddl.ID = z.ToString

ddl.DataSource = dstCust
ddl.DataTextField = "cust_name"
ddl.DataValueField = "cust_id"
ddl.DataBind()
AddHandler ddl.SelectedIndexChanged, AddressOf
ddl_SelectedIndexChanged
ddl.AutoPostBack = True
Next

Private Sub ddl_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddl.SelectedIndexChanged
Dim x As String = "This function is never called!!!!!!!"
End Sub

Apr 27 '06 #4
It is having post back.
Also I have some code in the page load event, this code is executed
only if
If Not IsPostBack Then

Apr 27 '06 #5
try removing the Handles ddl.SelectedIndexChanged from the event declaration
as well as WithEvents in the declaration.

How do you know the function is never called? Also are you getting any error
?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
<j_****@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
It is having post back.
Also I have some code in the page load event, this code is executed
only if
If Not IsPostBack Then

Apr 27 '06 #6
There is no state between page requests - every page gets recreated from
scratch again.

Remove the Not IsPostBack check and you should be fine.
Attached is the code I was testing on my side

I used a panel to add the controls in the aspx
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Panel Runat="server" ID="pnlTest"></asp:Panel>
</form>
</body>
Code-behind :
Protected pnlTest As Panel

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim z As Integer

For z = 0 To 10

Dim ddl As System.Web.UI.WebControls.DropDownList = New
System.Web.UI.WebControls.DropDownList

ddl.Style("width") = "150"

ddl.ID = z.ToString

ddl.DataSource = GetData()

ddl.DataTextField = "cust_name"

ddl.DataValueField = "cust_id"

ddl.DataBind()

AddHandler ddl.SelectedIndexChanged, AddressOf ddl_SelectedIndexChanged

ddl.AutoPostBack = True

pnlTest.Controls.Add(ddl)

Next

End Sub

Public Sub ddl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs)

Dim x As String = "This function is never called!!!!!!!"

End Sub

Private Function GetData() As DataSet

'Some data --replace with your own

Dim ds As New DataSet

Dim dt As New DataTable

dt.Columns.Add(New DataColumn("cust_name"))

dt.Columns.Add(New DataColumn("cust_id"))

Dim dtRow As DataRow = dt.NewRow

dtRow(0) = "1"

dtRow(1) = "1"

dt.Rows.Add(dtRow)

dtRow = dt.NewRow

dtRow(0) = "2"

dtRow(1) = "2"

dt.Rows.Add(dtRow)

ds.Tables.Add(dt)

Return ds

End Function
Hope this helps!
--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
<j_****@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
It is having post back.
Also I have some code in the page load event, this code is executed
only if
If Not IsPostBack Then

Apr 27 '06 #7
So this is my problem.
I didn't create drop down on Page Load event.
Thanks for your help.

Apr 27 '06 #8
Does that mean that fixed your problem ?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
<j_****@hotmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
So this is my problem.
I didn't create drop down on Page Load event.
Thanks for your help.

Apr 27 '06 #9
Yes, thanks

Apr 27 '06 #10

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

Similar topics

1
by: Donal | last post by:
I have 3 related dropdowns. When the 1st is changed, the 2nd is updated, and when the 2nd is changed, the 3rd is updated. When i change the 1st dropdown (sites), the SelectedIndexChanged fires...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
2
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.....
0
by: Tand35006 | last post by:
Hi, I hope some one can help with this. I have a basic webform with 2 DropDownLists and a single DataGrid. What I am trying to do is populate the first DDList from a dataset on Form_Load. I then...
1
by: sergeyr3 | last post by:
Hey guys, I am new here, so i hope this works out: I have a datagrid which I populate with data from XML file. In EditItemTemplate I have a dropdownlist. How do I fire myDataGrid_UpdateCommand...
4
by: David | last post by:
Hi all, I am doing this in a web page... I have a dropdownlist that autopostback. This sets me a filter criteria for items to display in a datalist. In the datalist, I have edit...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
5
by: Victorious1 | last post by:
Why doesn't the the SelectedIndexchanged event for my dropdownlist ever get executed? Why do I get a page not found error when I select a new item? My dropdownlist is within a form. The items...
2
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some...
5
by: revbart | last post by:
Yep, that's me. I'll bet I've read a hundred articles somewhere or another, but I just can't get the thing to work. I'm working on a custom solution. One of the major UIs includes a calendar-style...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.