I need to check every row of a datalist on a button click to check if the checkbox inside the e开发者_如何学运维ach row is checked or not. I put my buttons inside the FooterTemplate of the DataList but I couldn't find a way yet. This is my ItemCommand method;
protected void DataList1_ItemCommand(object sender, DataListCommandEventArgs e) {
if (e.Item.ItemType == ListItemType.Footer) {
if (e.CommandName == "AddContinue") {
} else if (e.CommandName == "SkipContinue") {
}
}
}
here is my footer;
<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>
Ok, apparently I was a little careless for not seeing DataList.Items
thing. Answer is sitting here;
http://blog.ysatech.com/post/2011/06/03/ASPNET-Get-selected-checkbox-value-in-DataList.aspx
EDIT
For others who has the same problem, here is the code;
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") {
}
}
}
精彩评论