2011-06-20 99 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()); 
    } 
}