2011-06-20 31 views
2

我檢查了所有的答案,但我的問題似乎不同 - 我有兩組複選框列表。在啓動時,我禁用了第二組中的所有複選框。ASP.net checkboxlist沒有得到檢查值

rotected void exchList_OnDataBound(object sender, EventArgs e) 
{ 
    for (int i = 0; i < exchList.Items.Count; i++) 
    { 
     exchList.Items[i].Attributes.Add("onclick", "gridCallback();"); 
     exchList.Items[i].Enabled = false; 
    }//end for 
}//end exchList_OnDataBound() 

選中第一組中的方框可以在另一方框中啓用方框。這是通過jQuery完成的。

$('#<%= exchList.ClientID %> input:checkbox').each(function() { 
      $label = $(this).parent().children("label").text(); 
      i = 0; 
      while(i < $jsonData.xxx.length) 
      { 
       if ($(this).attr('disabled')) 
      { 
       $(this).removeAttr('disabled'); 
      $(this).attr('checked', 'checked'); 
       }//end if 
      else 
      { 
       $(this).removeAttr('checked'); 
       $(this).attr('disabled', 'disabled'); 
      }//end else 
       i++; 
      }//end while 
    }); 

雖然在回調過程中要檢查的方框沒有被檢測到。

protected void productGrid_OnCustomCallback(object sender, 
         DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e) 
{ 
    String markets = "", exchs = ""; 
    int i; 
    for (i = 0; i < marketList.Items.Count; i++) 
    { 
     if (marketList.Items[i].Selected) 
      System.Diagnostics.Debug.WriteLine(marketList.Items[i].Text); 
    }//end for 

    for (i = 0; i < exchList.Items.Count; i++) 
    { 
     System.Diagnostics.Debug.WriteLine(exchList.Items[i].Text + " " + exchList.Items[i].Enabled); 
    }//end for 
}//end productGrid_OnCustomCallback() 

即使複選框被清楚檢查,它們也不會被檢查。看着螢火蟲顯示,因爲我禁用並啓用了列表項目,複選框被DIV封裝,這可能會導致問題。我在沒有禁用/啓用的情況下測試了它,並且HTML沒有圍繞複選框的DIV,現在它可以正常工作。我如何從listitem中獲得DIV內的複選框選中值?

回答

1

如果我沒有記錯,這是某種形式的ASP.net的錯誤的控制,如果一個複選框在頁面加載禁用,它總是返回爲未選中,即使你啓用它,並檢查它的客戶端。
解決方法是從服務器端發送啓用的複選框,並在必要時在客戶端加載時禁用它們。

恕我直言,一個prefferable的解決辦法是,當然,不使用ASP.net控制所有的,因爲我覺得他們過於複雜和超重。但hey-這只是我......

+0

但我怎麼能生成一個複選框列表而不使用asp.net checkboxlist?我逼債想用javascript ... – Ron

+1

好了,如果你不想使用的客戶端代碼生成的客戶端,然後...是啊,你幾乎堅持與服務器端控件:)控制。我個人用大量的JavaScript(jQuery的actually-)的,它具有更簡單,使用更方便,高效,然後asp.net的人很多控件。我建議你給它一個機會... –

-1

嘗試使用我使用的CheckBoxList這些代碼。它使用2頁。沒有jscript代碼..希望這有助於。 第一頁cs碼。

Session["checkedarray"] = new string[] { "1.0", "2.0", "3.0" }; 
      { 
       { 
        string[] checkedlist = new string[17]; 
        int a = 0; 

        for (int i = 0; i <= 16; i++) 
        { 
         if (cblist1.Items[i].Selected == true) 
         { 
          checkedlist[a] = cbllist1.Items[i].ToString(); 
          a = a + 1; 
         } 
        } 

        Session["checkedarray"] = checkedlist; 
        Session["numofchecked"] = a; 
        Response.Redirect("ReportPage2.aspx"); 
       } 
      } 

第2頁cs碼。

protected void Page_Load(object sender, EventArgs e) 
{ 
    string[] arr = (string[])Session["checkedarray"]; 

    for (int i = 0; i < int.Parse(Session["numofchecked"].ToString()); i++) 
    { 
     ColcbList2.Items.Add(arr[i].ToString()); 
    } 
}