如何将事件处理程序添加到循环DropDownList

时间:2017-06-23 10:58:54

标签: javascript jquery asp.net vb.net selectedindexchanged

我正在使用ASP.Net/VB.NET中的网站,该网站具有重复设计 - 用户必须为几个不同的主题输入相同类型的数据。

我无法让.SelectedIndexChange为我的应用程序工作。我想使用JavaScript / JQuery来实现这一点。

这是我现在拥有的代码,但不起作用。不会抛出任何错误,但永远不会调用AppChange()方法。

List.Items.Add("Choose...")
List.Items.Add("Yes")
List.Items.Add("No")
'List.AutoPostBack = True
'AddHandler List.SelectedIndexChanged, AddressOf ListChange

请注意我已经注释了最后两行,因为我正在尝试其他事情。

Dim ListID = String.Concat("ListOption", DBReader("nListID"))
List.ID = ListID
AddHandler List.SelectedIndexChanged, AddressOf ListChange
                                d.Controls.Add(List)

以下是更改事件的方法

Protected Sub ListChange(sender As Object, e As EventArgs)
        Label1.Text = "It worked"

    End Sub

源代码看起来像这样......

<td align="right" style="font-family:Calibri;">Options</td><td></td><td><select name="ListOption1" id="ListOption1" style="width:230px;">

所以显然有些东西没有注册,而且我不太清楚是什么。

2 个答案:

答案 0 :(得分:0)

您是否尝试过为子资源添加处理程序?

Private Sub ListChange(sender As Object, e As EventArgs) Handles ListChange.SelectedIndexChanged

    Label1.Text = "It worked"

End Sub

答案 1 :(得分:0)

我得到了开发人员导师的帮助,完成了这项任务。

<。>在.aspx文件中,你添加了这样的功能

l <- NULL
l$name <- c('b','e','d','b','b','d','e','e','b','b')
l$age <- c(20,20,21,21,20,22,22,30,21,32)
l$gender <- c('Female', 'Female', 'Male', 'Female', 'Male','Male', 
              'Female','Male',"Female","Male")

l <- as.data.frame(l)
l$name <- as.character(l$name)
l$age <- as.numeric(l$age)
l$gender <- as.character(l$gender)


library(shiny)
server <- shinyServer(function(input,output){

  observeEvent(input$reset, {
    reset("Box1") 
    reset("Box2") 
    reset("Box3")

  })

  # DEfinition of all values of my variables
  assign('All Names',unique(sort(l$name)))
  assign("All Ages", unique(sort(l$age)))
  assign('All Genders', unique(sort(l$gender)))


  data1 <- reactive({
    l[which(l$name %in% if(exists(input$name))
    {get(input$name)}else{input$name}),]
  })




  data2 <- reactive(data1()[which(data1()$age %in% if(exists(input$age))
  {get(input$age)}else{input$age}),])


  data3 <- eventReactive(input$baba, {
    data2()[which(data2()$gender %in% if(exists(input$gender))
    {get(input$gender)}else{input$gender}),]
  })

  output$table3 <- renderTable({
    data3()
  })


  output$Box1 =  renderUI(
    if((is.null(input$age)) & (is.null(input$gender))){
      selectInput("name", "Choose Name", choices=c("All Names",unique(sort(l$name))), selected = input$name)
    } else{selectInput("name", "Choose Name", choices=c("All Names",
                                                        unique(l[l$gender %in% (if(exists(input$gender)){
                                                          get(input$gender)
                                                          }else{
                                                            input$gender}) & 
                                                            l$age %in% (if(exists(input$age)){
                                                              get(input$age)
                                                              }else{input$age}), "name"])), selected = input$name)
    }
  )



  output$Box2 =  renderUI(
    if((is.null(input$name)) & (is.null(input$gender))){
      selectInput("age", "Choose Age", choices=c("All Ages", unique(sort(l$age))), selected = input$age)
    }else{selectInput("age", "Choose Age", choices=c("All Ages",unique(l[l$gender %in% (if(exists(input$gender)){get(input$gender)}else{input$gender}) & l$name %in% (if(exists(input$name)){get(input$name)}else{input$name}) , "age"])), selected = input$age)}
  )


  output$Box3 =  renderUI(
    if((is.null(input$name)) & (is.null(input$age))){
      selectInput("gender", "Choose Gender", choices=c("All Genders", unique(sort(l$gender))), selected = input$gender)
    }else{
      selectInput("gender", "Choose Gender", choices=c("All Genders", unique(l[l$name %in% (if(exists(input$name)){get(input$name)}else{input$name}) & l$age %in% (if(exists(input$age)){get(input$age)}else{input$age}), "gender"])), selected = input$gender)
    }
  )



})

ui <-shinyUI(fluidPage(
  useShinyjs(),
  uiOutput("Box1"),
  uiOutput("Box2"),
  uiOutput("Box3"),
  actionButton("baba", "GO !"),
  actionButton("reset", "reset"),
  tableOutput("table3")
))

shinyApp(ui,server)

,在.aspx.vb文件中,

<script type="text/javascript">
    function Change(value, id)
    {
        alert("It worked");
    }
</script>
相关问题