AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 DropDownList Inside GridView Inside UpdatePanel SelectedIndexChanged Event not firing
Posted by Sara on  8/16/2010 9:19:58 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Hi everyone,
I have an UpdatePanel with a GridView. This GridView has a template column that is a DropDownList. The problem is that the SelectedIndexChanged event does not fire for the DropDownList.

Where am I wrong?

Here is the code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Prova.aspx.vb" Inherits="Prova" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>NUMBERS</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="scrManager" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updPnl" runat="server">
<ContentTemplate>
<asp:GridView ID="grdNumber" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlNumber" runat="server" OnSelectedIndexChanged="ddlNumber_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
<asp:ListItem>For</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

And here is the codebehind:

Imports System.Data

Partial Class Prova
Inherits System.Web.UI.Page


Protected Sub ddlNumber_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim ddl As DropDownList
ddl = sender
MsgBox(ddl.SelectedValue)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim dt As New DataTable

dt.Rows.Add()
dt.Rows.Add()
dt.Rows.Add()
dt.Rows.Add()

Me.grdNumber.DataSource = dt
Me.grdNumber.DataBind()
End Sub
End Class

Post Your Reply Post New Question

 Viewer's Reply
Add IsPostBack in Page Load Event
Answered By Moderator1 on 8/17/2010 12:04:45 AM
Hi,

Add all the codes inside the Page_Load event inside an IsPostBack condition. Then I hope you will get the SelectedIndexChanged event to fire.

Btw, what does MsgBox do here?
 
It works!
Answered By Sara on 8/17/2010 11:02:32 AM
Thanx, it works perfectly! MsgBox is for debug purposes only, I know is a server-side function.
I come for desktop development, this is my first web project :P
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Web Application Security — How to Minimize Prevalent Risk of Attacks
Simply SQL - Free 111 Page Preview!
Easing the Migration to Microsoft SQL Server 2005