Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Dropdownlist SelectedIndexChanged event

Reply
Thread Tools

Dropdownlist SelectedIndexChanged event

 
 
Halvor Nyberg
Guest
Posts: n/a
 
      09-29-2003
Hi,
I want to respond when the user picks another item in the
dropdownlist.

In the html section I got:
... SelectedIndexChanged="MyListChange"
(see example below)

I the script section I have the sub
sub MyListChange

MyListChange is not triggered after the Postback.
Is this logical, or have I missed something?

thanks.


<%@ Page Language="VB" %>
<script runat="server">

dim t_resp as string

Sub Page_Load(Sender As Object, E As EventArgs)


If Not Page.IsPostBack Then

dim i as integer
Dim myList As New ArrayList()
for i=0 to 10
myList.add("Test " & i)
next
DropDownList1.DataSource = myList
DropDownList1.DataBind()
datagrid1.DataSource = myList
datagrid1.DataBind()
else
t_resp="Post back Only"
End If


End Sub

Sub ApplyFilter_Click(Sender As Object, E As EventArgs)
t_resp= ("Apply button: " &
DropDownList1.SelectedItem.Text)
msgbox(t_resp)
end sub

public sub MyListChange(sender As Object, e As
EventArgs)
t_resp=("Dropdown Change: " &
DropDownList1.SelectedItem.Text)

end sub

</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>test
</h2>
<hr size="1" />
<form id="F1" runat="server" EnableViewState="true">
<p>
Test&nbsp;<aspropDownList id="DropDownList1"
runat="server" SelectedIndexChanged="MyListChange"
AutoPostBack="true" EnableViewState="true"
Width="235px"></aspropDownList>
&nbsp; <asp:Label id="lblCur" runat="server"
forecolor="Red"> </asp:Label>
</p>
<p>
Test:
<asp:TextBox id="TextBox2"
runat="server"></asp:TextBox>
<asp:Button id="Button1"
onclick="ApplyFilter_Click" runat="server"
Text="Show"></asp:Button>
</p>
<asp:datagrid id="DataGrid1" runat="server"
EnableViewState="true" CellSpacing="1" GridLines="None"
CellPadding="3" BackColor="White" ForeColor="Black"
AutoGenerateColumns="True">
<HeaderStyle font-bold="True"
forecolor="white" backcolor="#4A3C8C"></HeaderStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>
<%response.write(t_resp)%><%%>
</form>
</body>
</html>

 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      09-30-2003
Hi Halvor,

You made a typo... you wanted onselectedindexchanged. My version is below.

Does this help?

Ken
MVP [ASP.NET]

<%@ Page Language="vb" AutoEventWireup="true" %>
<html>
<head>
<script runat="server">
dim t_resp as string
Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
dim i as integer
Dim myList As New ArrayList()
for i=0 to 10
myList.add("Test " & i)
next
DropDownList1.DataSource = myList
DropDownList1.DataBind()
datagrid1.DataSource = myList
datagrid1.DataBind()
else
t_resp="Post back Only"
End If
End Sub

Sub ApplyFilter_Click _
(Sender As Object, E As EventArgs)
t_resp= ("Apply button: " & _
DropDownList1.SelectedItem.Text)
' msgbox(t_resp)
end sub

public sub MyListChange _
(sender As Object, e As EventArgs)
t_resp=("Dropdown Change: " & _
DropDownList1.SelectedItem.Text)
end sub

</script>
</head>
<body style="FONT-FAMILY: arial">
<h2>test
</h2>
<hr size="1">
<form id="F1" runat="server">
<p>
Test&nbsp;<asp:dropdownlist id="DropDownList1" runat="server"
onselectedindexchanged="MyListChange" autopostback="true"
enableviewstate="true" width="235px"></asp:dropdownlist>
&nbsp;
<asp:label id="lblCur" runat="server" forecolor="Red"></asp:label>
</p>
<p>
Test:
<asp:textbox id="TextBox2" runat="server"></asp:textbox>
<asp:button id="Button1" onclick="ApplyFilter_Click" runat="server"
text="Show"></asp:button>
</p>
<asp:datagrid id="DataGrid1" runat="server" enableviewstate="true"
cellspacing="1" gridlines="None"
cellpadding="3" backcolor="White" forecolor="Black"
autogeneratecolumns="True">
<headerstyle font-bold="True" forecolor="white"
backcolor="#4A3C8C"></headerstyle>
<itemstyle backcolor="#DEDFDE"></itemstyle>
</asp:datagrid>
<%response.write(t_resp)%>
<%%>
</form>
</body>
</html>


--

Help stop SWEN in the newsgroups - Get the W32.Swen.A@mm Removal Tool:
http://securityresponse.symantec.com...oval.tool.html


"Halvor Nyberg" <(E-Mail Removed)> wrote in message
news:012b01c38697$53a12800$(E-Mail Removed)...
Hi,
I want to respond when the user picks another item in the
dropdownlist.

In the html section I got:
... SelectedIndexChanged="MyListChange"
(see example below)

I the script section I have the sub
sub MyListChange

MyListChange is not triggered after the Postback.
Is this logical, or have I missed something?

thanks.




 
Reply With Quote
 
 
 
 
jeroen
Guest
Posts: n/a
 
      09-30-2003
Olso don't forget to set the Autopostback property of your
control to TRUE, otherwise it won't fire a postback.
 
Reply With Quote
 
Halvor Nyberg
Guest
Posts: n/a
 
      09-30-2003
Thanks Ken !
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dropdownlist selectedindexchanged event not firing.. please help. DesignerX ASP .Net 2 11-14-2003 03:25 PM
SelectedIndexChanged event in DropDownList Pepito Grillo ASP .Net 0 07-28-2003 08:36 AM
Re: Dropdownlist SelectedIndexChanged event problem Robert Hanson ASP .Net 0 07-10-2003 10:58 PM
Dropdownlist SelectedIndexChanged event problem Robert Hanson ASP .Net 0 07-10-2003 08:28 PM
Catching an SelectedIndexChanged event from a DropDownList inside a DataGrid Dominic ASP .Net 2 07-04-2003 04:43 AM



Advertisments