2012-03-15 52 views
0

我在其中一個網頁中使用複選框和複選框列表。ASP.net UI刷新問題

的UI就像

顏色 - 頭複選框

CheckBoxList的項目

綠色

完整選擇 - 點擊標題複選框選擇/取消選擇整個複選框列表。

對複選框列表的部分選擇顯示了具有不同背景顏色的標題複選框,以指示部分選擇。

我會檢查每個複選框列表選擇更改中選定項目的數量。在客戶端服務器環境中,存在時間延遲,並且如果我們在複選框列表中進行了兩次連續選擇,則會爲第一次選擇完成標題控件的更新,並且在刷新UI時,第二次選擇將消失。 我也使用JavaScript實現了上面的一個,但同樣的行爲也是一樣的。 有什麼可以替代呢?

+0

我讀了兩遍,還是不知道你在說什麼。 http://www.whathaveyoutried.com – Marc 2012-03-15 12:02:18

+0

你正在談論哪個屏幕截圖? – 2012-03-15 12:08:44

+0

需要一些更多的信息。你想達到什麼目的?現場發生了什麼(點擊複選框)等。 – 2012-03-15 12:53:11

回答

0

你的問題不是特別清楚,但它聽起來像你想要某種三態複選框?這聽起來像回發正在發生,並消除你的第二選擇?

如果是這樣,那裏有一些控制選項。這裏有一個可能有所幫助的鏈接。 http://www.chadscharf.com/index.php/2008/10/3-state-checkbox-using-microsoft-ajax/

您確實需要發佈一些代碼並鏈接到您提到的屏幕截圖。

+0

感謝您的答覆。是我試圖實現像三個狀態複選框。我無法附上截圖。 – MithunRaj 2012-03-15 17:18:02

0

有兩種情況你試圖滿足,最簡單的方法是利用Javascript。當然,一個方向是使用Jquery來簡化DOM元素的連接。

下面是一個例子,它涵蓋了兩種情況。一個頂層控件檢查/取消選中所有元素。其次,個人改變了頂級元素的背景。這不是丟棄和運行代碼,它只是單獨演示技術。如果您不熟悉Jquery,只需在Jquery網站上搜索每個功能,即可對我進行更改和調整。請享用!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script> 

    <script type="text/javascript"> 
     $(document).ready(function(){  

      // Wire up the 'select-all' to the child elements 
      $('#topLevel').bind('change' , function(){ 
       // Record this object 
       var base = this; 
       // Change the child elements 
       $('#checkboxContainer input').each(function(){ 
        $(this).attr('checked' , $(base).is(':checked')) 
       })     
      }); 

      // Make the individual checkbox selects alter the 
      // background of the top-level wrapper 
      $('#checkboxContainer input').bind('change' , function(){ 
       // Get a handle to the top item 
       var topLevel = $('#topLevelWrapper');     
       // Have we selected the item? 
       if($(this).is(':checked')){ 
        // Remove the previous class assignments 
        topLevel.attr('class' , ''); 
        // Assign the current css class from the parent 
        topLevel.addClass($(this).parent().attr('class'));       
       } 
      }); 

     }) 
    </script> 

    <style type="text/css"> 
     .Red{ 
      background-color:#F00; 
     } 
     .Green{ 
      background-color:#0F0; 
     } 
     .Blue{ 
      background-color:#00F; 
     } 
    </style> 
</head> 
<body> 

    <div id="topLevelWrapper"> 
     <label for="topLevel">Top level selection</label> 
     <input type="checkbox" id="topLevel" /> 
    </div> 

    <div id="checkboxContainer"> 
     <ul> 
      <li class="Red"> 
       <label for="topLevel">Red</label> 
       <input type="checkbox" /> 
      </li> 
      <li class="Blue"> 
       <label for="topLevel">Blue</label> 
       <input type="checkbox" /> 
      </li> 
      <li class="Green"> 
       <label for="topLevel">Green</label> 
       <input type="checkbox" /> 
      </li> 

     </ul> 

    </div> 

</body>