我檢查了所有的答案,但我的問題似乎不同 - 我有兩組複選框列表。在啓動時,我禁用了第二組中的所有複選框。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的人很多控件。我建議你給它一個機會... –