Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    10

    SelectedIndexChanged per DropDownList in GridView in UpdatePanel

    Ciao a tutti,
    ho un GridView in un UpdatePanel. Questo GridView ha una template column che è una DropDownList. Il problema è che l'evento SelectedIndexChanged della DropDownList non viene scatenato.

    Dove sbaglio?

    Ecco il codice:

    codice:
    <%@ 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>
    E qui c'è il codebehind:

    codice:
    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

  2. #2
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    questo è l'esempio che ho provato io
    codice:
    Option Strict On
    Imports l = libreria.ModuloWeb
    
    Partial Class prove_a
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Me.IsPostBack Then
                msole.DataBind(Me.grdNumber, gl.StringaConnessione, "select * from campi", Nothing)
            End If
    
    
        End Sub
    
        Protected Sub ddlNumber_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim b As DropDownList = DirectCast(sender, DropDownList)
    
            l.MsgBox(Me, b.SelectedValue)
        End Sub
    
    End Class
    ossia, nell'evento load
    If Not Me.IsPostBack Then
    DataBind
    end if
    Pietro

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    10
    Perfetto, funziona, grazie!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.