uncheck the checkbox when deleting the gridview row
Dec 22, 2020 01:37 AM|anjaliagarwal5@yahoo.com|LINK
Hello All,
I have a gridview and a checkbox outside the gridview. When I delete a row in the gridview, I want the checkbox to be unchecked if it is checked. Some how the checkbox does not get unchecked when I delete the gridview row. It works if the gridview is not
enclosed in updatePanel otherwsie, it does not work.
protected void grdShoppingCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
// this handler will be triggered as well
var rowNum = e.RowIndex;
chkat.Checked = false;
DataRow row = _gridviewDT.Rows[rowNum];
_gridviewDT.Rows.Remove(row);
grdShoppingCart.DataSource = _gridviewDT;
grdShoppingCart.DataBind();
}
And I add some code in RowDeleting event for testing.
This is result:
Hope this can help you.
Best regards,
Xudong Peng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
506 Points
1259 Posts
uncheck the checkbox when deleting the gridview row
Dec 22, 2020 01:37 AM|anjaliagarwal5@yahoo.com|LINK
Hello All,
I have a gridview and a checkbox outside the gridview. When I delete a row in the gridview, I want the checkbox to be unchecked if it is checked. Some how the checkbox does not get unchecked when I delete the gridview row. It works if the gridview is not enclosed in updatePanel otherwsie, it does not work.
below is the gridview and the code behind:
code behind:
when I do chkat.Checked = false; then the checkbox does not get unchecked. It stays checked. Bleow is the image:
I want the confirm check box to unchecked when the row is deleeted.
any help will be highly appreciated.
Participant
1780 Points
561 Posts
Re: uncheck the checkbox when deleting the gridview row
Dec 22, 2020 06:17 AM|XuDong Peng|LINK
Hi anjaliagarwal5,
According to your description, I create a simple demo.
If I don’t understand what you mean, please refer to the following code:
<body> <form id="form1" runat="server"> <div> <asp:ScriptManager runat="server"></asp:ScriptManager> <asp:UpdatePanel runat="server" ID="UpdInfo" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="grdShoppingCart" runat="server" AutoGenerateColumns="false" class="ui-responsive table-stroke ss-table ui-search-result-table" DataKeyNames="CartID" AllowPaging="false" PageSize="5" GridLines="None" OnRowCommand="grdShoppingCart_RowCommand" OnRowDataBound="grdShoppingCart_RowDataBound" OnRowDeleting="grdShoppingCart_RowDeleting"> <Columns> <asp:BoundField HeaderText="ID" DataField="CartID" /> <asp:BoundField HeaderText="Name" DataField="Name" /> <asp:TemplateField ShowHeader="False" HeaderStyle-HorizontalAlign="center" ItemStyle-HorizontalAlign="center" ItemStyle-Width="150px" ControlStyle-CssClass="ss-row"> <ItemTemplate> <asp:HiddenField ID="hf_id" runat="server" Value='<%#Eval("CartID") %>' /> <asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/Images/delete1.png" ToolTip="Click To Delete" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this event?');" AlternateText="Delete" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="grdShoppingCart" /> </Triggers> </asp:UpdatePanel> </div> <asp:CheckBox ID="chkat" runat="server" Text="confirm" /> </form> </body>
protected void grdShoppingCart_RowDeleting(object sender, GridViewDeleteEventArgs e) { // this handler will be triggered as well var rowNum = e.RowIndex; chkat.Checked = false; DataRow row = _gridviewDT.Rows[rowNum]; _gridviewDT.Rows.Remove(row); grdShoppingCart.DataSource = _gridviewDT; grdShoppingCart.DataBind(); }
And I add some code in RowDeleting event for testing.
This is result:
Hope this can help you.
Best regards,
Xudong Peng
Member
506 Points
1259 Posts
Re: uncheck the checkbox when deleting the gridview row
Dec 22, 2020 04:42 PM|anjaliagarwal5@yahoo.com|LINK
Thank You!