单击按钮时遍历 DataList 控件的所有行
我需要单击按钮检查数据列表的每一行,以检查每行内的复选框是否已选中。我将按钮放在 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>
I need to check every row of a datalist on a button click to check if the checkbox inside the each 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,显然我有点粗心,没有看到
DataList.Items
东西。答案就坐在这里;http://blog .ysatech.com/post/2011/06/03/ASPNET-Get-selected-checkbox-value-in-DataList.aspx
编辑
对于其他有相同情况的人问题,这是代码;
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;