单击按钮时遍历 DataList 控件的所有行

发布于 2024-11-16 02:07:57 字数 1396 浏览 3 评论 0原文

我需要单击按钮检查数据列表的每一行,以检查每行内的复选框是否已选中。我将按钮放在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带刺的爱情 2024-11-23 02:07:57

好吧,显然我有点粗心,没有看到 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") {


            }

        }

    }

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") {


            }

        }

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文