简体   繁体   English

在 ASP.NET C# 中取消选中中继器数据表中的行

[英]Uncheck rows in Repeater DataTable in ASP.NET C#

I have a data table filled using a Repetear.我有一个使用 Repetear 填充的数据表。 Also one column contains a checkbox property to select rows and, with a button, insert the checked rows into another table.此外,一列包含一个复选框属性,用于选择行,并使用按钮将选中的行插入到另一个表中。 After that, I use Response.Redirect("Page.aspx") to restart everything.之后,我使用Response.Redirect("Page.aspx")重新启动一切。 Is there a way to uncheck all the rows and clean the search result of the table without reload the page??有没有办法在不重新加载页面的情况下取消选中所有行并清理表格的搜索结果? The table fills with 30,000 records and the page takes to much to load.该表填充了 30,000 条记录,页面加载时间过长。

aspx: ASP:

<div class="panel panel-default">
    <div class="panel-heading">
        Data Table #1
    </div>

    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-striped table-bordered table-hover" id="dataTables-StockAlmacen" data-toggle="table" data-sort-name="aiuda" data-sort-order="desc">
                <thead>
                    <tr>               
                        <th>Seleccionar</th>
                        <th>Id_Parte</th>
                        <th>Stock</th>
                        <th>Planta</th>
                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="rptStockAlmacen" runat="server">
                        <ItemTemplate>
                            <tr>
                                
                                <td>
                                    <asp:CheckBox ID="chkSeleccionar" runat="server" />
                                </td>
                                <td>
                                    <asp:Label ID="lblId_Parte" runat="server" Text='<%# Eval("Id_Parte") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="lblStock" runat="server" Text='<%# Eval("Stock") %>' />
                                </td>

                                <asp:HiddenField ID="hiddenSeleccionar" runat="server" Value='<%#Eval("Id_Parte") %>' />

                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
            </table>
        </div>
    </div>
</div>

aspx.cs: aspx.cs:

protected void btnInsertar_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem i in rptStockAlmacen.Items)
        {
            CheckBox cb = (CheckBox)i.FindControl("chkSeleccionar");
            if (cb.Checked)
            {
                HiddenField hiddenSeleccionar = (HiddenField)i.FindControl("hiddenSeleccionar");
                SqlComm.SqlExecuteQueryInsert("insert into PartesSupervisadas (Id_Parte) values ('" + Int32.Parse(hiddenSeleccionar.Value) + "');");
            }
        }
       
        Response.Redirect("StockAlmacen.aspx");

    }

Ouch you need to implement paging first and foremost.哎哟你首先需要实现分页。 After that you could either call a js function to look for all checkboxes and clear them, you can do it on load or create a button that the user can click which fires the event.之后,您可以调用 js 函数来查找所有复选框并清除它们,您可以在加载时执行此操作,也可以创建一个用户可以单击以触发事件的按钮。 Eg below例如下面

 function uncheckMe()
 { 
    var checkBox = document.getElementsByTagName('input'); 
    for(var i = 0; i < checkBox.length; i++)
    { 
      if(checkBox[i].type =='checkbox')
      { 
        checkBox[i].checked = false; 
      }
    }
 } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM