我需要在按钮上单击检查数据列表的每一行,以检查是否选中了每行内的复选框。我把我的按钮放在DataList的FooterTemplate中,但我找不到方法。这是我的ItemCommand方法;
protected void DataList1_ItemCommand(object sender, DataListCommandEventArgs e) {
if (e.Item.ItemType == ListItemType.Footer) {
if (e.CommandName == "AddContinue") {
} else if (e.CommandName == "SkipContinue") {
}
}
}
这是我的页脚;
<FooterTemplate>
<div class="top-margin-25">
<div class="left-floathy">
<asp:Button runat="server" ID="btnPreviousStep" Text="<<< Previous Page"
class="blueButtonSmall boxShadow" onclick="btnPreviousStep_Click" />
</div>
<div class="right-floathy">
<asp:Button runat="server" ID="btnAddContinue" Text="Add & Contuniue >>>"
class="blueButtonSmall boxShadow" CommandName="AddContinue" /><br />
</div>
<div class="clarFix"></div>
<div class="right-floathy">
<asp:Button runat="server" ID="btnSkipContinue" Text="Skip & Continue >>>"
class="blueButtonSmall boxShadow" CommandName="SkipContinue" />
</div>
<div class="clarFix"></div>
</div>
</FooterTemplate>
答案 0 :(得分:1)
好吧,显然我因为没有看到DataList.Items
事而有点粗心。答案就坐在这里;
http://blog.ysatech.com/post/2011/06/03/ASPNET-Get-selected-checkbox-value-in-DataList.aspx
修改强>
对于遇到同样问题的其他人,这是代码;
protected void DataList1_ItemCommand(object sender, DataListCommandEventArgs e) {
if (e.Item.ItemType == ListItemType.Footer) {
if (e.CommandName == "AddContinue") {
foreach (DataListItem item in DataList1.Items) {
CheckBox extraCheck
= item.FindControl("extraCheck") as CheckBox;
if (extraCheck != null) {
if (extraCheck.Checked) {
Response.Write(item.ItemIndex);
}
}
}
} else if (e.CommandName == "SkipContinue") {
}
}
}