我检查了所有的答案,但我的问题似乎不同 - 我有两组复选框列表。在启动时,我禁用了第二组中的所有复选框。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内的复选框选中值?
但我怎么能生成一个复选框列表而不使用asp.net checkboxlist?我逼债想用javascript ... – Ron
好了,如果你不想使用的客户端代码生成的客户端,然后...是啊,你几乎坚持与服务器端控件:)控制。我个人用大量的JavaScript(jQuery的actually-)的,它具有更简单,使用更方便,高效,然后asp.net的人很多控件。我建议你给它一个机会... –