受保护的子名称.ValueChanged不更新

时间:2016-07-30 00:17:45

标签: html asp.net vb.net

为什么当用户从下拉列表中选择不同的选项时,Line1Co.Value始终保持为0?

这是我的HTML:

       <asp:DropDownList ID="HandLine1Size" runat="server" AutoPostBack="true" Width="110px">
            <asp:ListItem Value="1">1.75</asp:ListItem>
            <asp:ListItem Value="1.5625">2</asp:ListItem>
            <asp:ListItem Value="2.25">2.5</asp:ListItem>
            <asp:ListItem Value="3.0625">3</asp:ListItem>
            <asp:ListItem Value="0">No handline</asp:ListItem>
        </asp:DropDownList
<asp:HiddenField ID="Line1Co" runat="server" />
<br />
    <%= Line1Co.Value %>

这是我的代码背后:

Protected Sub Line1Co_ValueChanged(sender As Object, e As EventArgs) Handles Line1Co.ValueChanged
    If HandLine1Size.SelectedValue = "1" Then Line1Co.Value = "12" Else 
    If HandLine1Size.SelectedValue = "1.5625" Then Line1Co.Value = "8" Else 
    If HandLine1Size.SelectedValue = "2.25" Then Line1Co.Value = "2" Else 
    If HandLine1Size.SelectedValue = "3.0625" Then Line1Co.Value = "0.75" Else 
    Line1Co.Value = "20"
End Sub

1 个答案:

答案 0 :(得分:0)

我在你的代码中看到两个问题:

  1. 您应该处理DropDownList的#include <iostream> #include <string> #include <stdio.h> #include <ctype.h> using namespace std; void sort(char letters[], int integers[], int size); void swap_letters(char& first, char& second, int& int1, int& int2); int index_of_largest(const int integers[], int start_index, int number_used); int main(){ const int MAX_CHARS = 200; char letters[MAX_CHARS] = {'\0'}; int integers[MAX_CHARS] = {'\0'}; int index, size = 0; char character; cout << "Enter text:" << endl; cin.get(character); character = tolower(character); while (character!= '.' && size < MAX_CHARS){ if(isalpha(character)){ index = 0; while (index < size){ if(letters[index] == character) break; else index++; } if (index < size){ integers[index] = integers[index] + 1; } else{ letters[index] = character; integers[index] = 1; size++; } } cin.get(character); character = tolower(character); } letters[index] = tolower(letters[index]); sort(letters, integers, size); cout << "Frequencies:"<< endl; for(int i = 0; i < size; i++){ cout << letters[i] << " " << integers[i] << endl; } return 0; } void sort(char letters[], int integers[], int size){ for (int i = 0; i < size -1; i++){ int j = index_of_largest(integers, i, size); swap_letters(letters[i], letters[j], integers[i], integers[j]); } } void swap_letters(char& first, char& second, int& int1, int& int2){ char temp_char = first; first = second; second = temp_char; int temp_int = int1; int1 = int2; int2 = temp_int; } int index_of_largest(const int integers[], int start_index, int number_used){ int max_int = integers[start_index]; int max_int_index = start_index; for (int index = start_index + 1; index < number_used; index++){ if (integers[index] > max_int){ max_int = integers[index]; max_int_index = index; } } return max_int_index; } 而不是HiddenField的SelectedIndexChanged事件。

  2. 单行ValueChanged语句对我来说看起来不对,最后是if。始终执行最后一行,并且在所有情况下将值设置为Else

  3. <小时/> 以下是实现目标的几种方法。

    使用单行"20"语句:

    if

    使用多行Protected Sub HandLine1Size_SelectedIndexChanged(sender As Object, e As EventArgs) Handles HandLine1Size.SelectedIndexChanged Line1Co.Value = "20" If HandLine1Size.SelectedValue = "1" Then Line1Co.Value = "12" If HandLine1Size.SelectedValue = "1.5625" Then Line1Co.Value = "8" If HandLine1Size.SelectedValue = "2.25" Then Line1Co.Value = "2" If HandLine1Size.SelectedValue = "3.0625" Then Line1Co.Value = "0.75" End Sub 声明:

    if

    使用Protected Sub HandLine1Size_SelectedIndexChanged(sender As Object, e As EventArgs) Handles HandLine1Size.SelectedIndexChanged If HandLine1Size.SelectedValue = "1" Then Line1Co.Value = "12" ElseIf HandLine1Size.SelectedValue = "1.5625" Then Line1Co.Value = "8" ElseIf HandLine1Size.SelectedValue = "2.25" Then Line1Co.Value = "2" ElseIf HandLine1Size.SelectedValue = "3.0625" Then Line1Co.Value = "0.75" Else Line1Co.Value = "20" End If End Sub 声明:

    Select