2011-06-27 11 views
0

いくつかの単純なコードを実行している.aspxファイルがあります。フォームを「送信」すると、ドロップダウンリストのコードに依存するラベル(lblCount)に情報が表示されます。何度も提出すると、ラベルが再作成されます。なぜなら、何らかの不動産が見つからない限り、私はそれを見ることができません。ラベルが再描画されないようにするプロパティはありますか?.aspxから送信するとラベルが再描画される

<html> 
<head runat="server"> 
    <title>Untitled Page</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
    <div> 
     <asp:Label runat="server" id="lblError" /> 
     <asp:DropDownList id="monthList" AutoPostBack = "True" runat = "server">    
      <asp:ListItem Selected = "True" Value = "January"> January </asp:ListItem> 
      <asp:ListItem Value = "February"> February </asp:ListItem> 
      <asp:ListItem Value = "March"> March </asp:ListItem> 
      <asp:ListItem Value = "April"> April </asp:ListItem> 
      <asp:ListItem Value = "May"> May </asp:ListItem> 
      <asp:ListItem Value = "June"> June </asp:ListItem> 
      <asp:ListItem Value = "July"> July </asp:ListItem> 
      <asp:ListItem Value = "August"> August </asp:ListItem> 
      <asp:ListItem Value = "September"> September </asp:ListItem> 
      <asp:ListItem Value = "October"> October </asp:ListItem> 
      <asp:ListItem Value = "November"> November </asp:ListItem> 
      <asp:ListItem Value = "December"> December </asp:ListItem> 
     </asp:DropDownList> 
     <asp:Label runat="server" id="lblCount" /> 
    </div> 
    <asp:Button ID="submitButton" OnClick="MonthSelection" Text="Submit" runat="server" /> 
    <div> 
    </div> 
</form> 
</body> 
</html> 

MONTHの選択:

protected void MonthSelection(object sender, EventArgs e) 
{ 
    dateLookup = monthList.SelectedItem.Value; 
    selectedMonth.Text = dateLookup.ToString(); 

    switch (dateLookup) 
    { 
     case "January": 
      monthDate = 01; 
      break; 
     case "February": 
      monthDate = 02; 
      break; 
     case "March": 
      monthDate = 03; 
      break; 
     case "April": 
      monthDate = 04; 
      break; 
     case "May": 
      monthDate = 05; 
      break; 
     case "June": 
      monthDate = 06; 
      break; 
     case "July": 
      monthDate = 07; 
      break; 
     case "August": 
      monthDate = 08; 
      break; 
     case "September": 
      monthDate = 09; 
      break; 
     case "October": 
      monthDate = 10; 
      break; 
     case "November": 
      monthDate = 11; 
      break; 
     case "December": 
      monthDate = 12; 
      break; 
    } 

    try 
    { 
     string sql = "SELECT COUNT(*) FROM members_ WHERE DATEPART(month, DateUnsub_) = " + monthDate + " AND DATEPART(year, DateUnsub_) = 2011 AND DATEDIFF(day, DateJoined_, DateUnsub_) <= 30"; 
     String[][] results = lm.SqlSelect(sql); 

     if (results != null) 
     { 
      for (int i = 0; i < results.Length; i++) 
      {     
       if (results[i] != null) 
       { 
        for (int j = 0; j < results[i].Length; j++) 
        {       
         if (results[i][j] != null) 
         { 
          if (results[i][j].Length > 5) 
           lblCount.Text += results[i][j]; 
          else 
           lblCount.Text += results[i][j]; 
         } 
        } 
       } 
      } 
     } 
    } 
    catch (SoapHeaderException ex) 
    { 
     lblError.Text = ex.Message; 
    } 
} 
+0

MonthSelection関数も参照する必要があります。 – Bill

+0

大丈夫 - そこに行く! –

+0

他のすべてのラベルは正常に動作しています。ただ1つのラベルがそれ自身を再印刷し続けることです。 –

答えて

0

私が間違っていたものを考え出した - それは私が実際に見ていなかった他人のコードでした。彼らは値に(+ =を使って)加算していました。私はちょうどプラスを取って、それは働いた。 sighすべてがそれほど小さくありません。

関連する問題