datgridview中的复选框在选中时不会重新刷新页面

时间:2019-03-17 14:48:40

标签: c# asp.net

我正在尝试遵循此示例https://www.aspsnippets.com/Articles/Transfer-Selected-Rows-from-one-GridView-to-Another-in-Asp.net.aspx,但是当选中复选框时,我的版本没有刷新页面。为什么?

这是我的前端代码,

<asp:GridView ID="gvPurchases" runat="server" AutoGenerateColumns="false" ShowFooter="true" onrowdatabound="gvPurchases_RowDataBound"
            ShowHeaderWhenEmpty="true" AllowPaging="True" OnPageIndexChanging="gridView_PageIndexChanging" DataKeyNames="compras_id"
             OnRowCommand="gvPurchases_RowCommand"  OnRowEditing="gvPurchases_RowEditing" OnRowCancelingEdit="gvPurchases_RowCancelingEdit"
            OnRowUpdating="gvPurchases_RowUpdating"  CellPadding="3" AllowUserToResizeColumns="True" PageSize="5" AllowSorting="true" onsorting="gvPurchases_Sorting"  GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
            <PagerSettings  Mode="Numeric"  />         
            <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                   <asp:CheckBox ID="chkRow" AutoPostBack="true" EnableViewState="true"  runat="server" onclick = "Check_Click(this)" OnCheckedChanged="CheckBox_CheckChanged" />
                       <%--<asp:CheckBox ID="chkRow" runat="server" />--%>
                    <asp:ImageButton ImageUrl="~/Images/edit.png" runat="server" CommandName="Edit" ToolTip="Edit" Width="20px" Height="20px"/>
                    <asp:ImageButton ImageUrl="~/Images/delete.png" runat="server" CommandName="Delete" ToolTip="Delete" Width="20px" Height="20px"/>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:ImageButton ImageUrl="~/Images/save.png" runat="server" CommandName="Update" ToolTip="Update" Width="20px" Height="20px"/>
                    <asp:ImageButton ImageUrl="~/Images/cancel.png" runat="server" CommandName="Cancel" ToolTip="Cancel" Width="20px" Height="20px"/>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:ImageButton ImageUrl="~/Images/addnew.png" runat="server" CommandName="AddNew" ToolTip="Add New" Width="20px" Height="20px"/>
                </FooterTemplate>
            </asp:TemplateField>   
             <asp:TemplateField HeaderText="Compras ID" SortExpression="compras_id">
                <ItemTemplate>                       
                    <asp:Label DataField="compras_id"  ID="lblPurschaseID" CssClass="gridTextbox" Text='<%# Eval("compras_id") %>' runat="server" />
                </ItemTemplate>
                <%--<EditItemTemplate>
                    <asp:TextBox CssClass="gridTextbox" ID="txtType" Text='<%# Eval("tipo") %>' runat="server" />
                </EditItemTemplate>--%>
                <FooterTemplate>
                    <asp:TextBox  CssClass="gridTextbox" ID="txtPurschaseIDFooter" runat="server" />
                </FooterTemplate>
            </asp:TemplateField>    
              <asp:TemplateField HeaderText="Contract Number" >
                <ItemTemplate>                       
                    <asp:Label DataField="numero_contrato"  ID="lblContractNumber" CssClass="gridTextbox" Text='<%# Eval("numero_contrato") %>' runat="server" />
                </ItemTemplate>
                <EditItemTemplate>   
            <asp:DropDownList  ID="drGridContractID" Runat="server"  AutoPostBack="false"  OnSelectedIndexChanged="DropDown_SelectedIndexChanged" />
                      <%-- <asp:TextBox CssClass="gridTextbox" ID="txtSupplier" Text='<%# Eval("nombre_proveedor") %>' runat="server" />--%>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox  CssClass="gridTextbox" ID="txtContractNumberFooter" runat="server" />
                </FooterTemplate>
            </asp:TemplateField> 

这是我的后端:

protected void CheckBox_CheckChanged(object sender, EventArgs e)
{
    GetData();
    SetData();
    BindSecondaryGrid();
}

但是,当选中复选框时,页面没有刷新,为什么?

1 个答案:

答案 0 :(得分:0)

我必须删除onclick =“ Check_Click(this)”来解决onClick没用的问题。

更改

 <asp:CheckBox ID="chkRow" AutoPostBack="true" EnableViewState="true"  runat="server" onclick = "Check_Click(this)" OnCheckedChanged="CheckBox_CheckChanged" />

 <asp:CheckBox ID="chkRow" AutoPostBack="true" EnableViewState="true"  runat="server" OnCheckedChanged="CheckBox_CheckChanged" />