locked
Delete record from child Gridview RRS feed

  • Question

  • User-1499457942 posted

    Hi

      How to Delete record from nested Gridview after confirmation.

    Thanks

    Monday, November 12, 2018 9:31 AM

All replies

  • User-1716253493 posted

    If you use sqldatasource it's automaticaly

    Tuesday, November 13, 2018 2:26 AM
  • User-1499457942 posted

    Hi oned_gk

      I have below code and i want to delete as link button . When user clicks on Delete button confirmation popup message should appear and then it should allow to delete

    <asp:GridView ID="gvwEmployee" OnPreRender="gvwEmployee_PreRender" runat="server"  CssClass="table table-bordered table-striped"
                     AutoGenerateColumns="false" OnRowCommand="gvwEmployee_RowCommand" OnRowDataBound="gvwEmployee_RowDataBound"
                    BorderWidth="1px"  BorderStyle="None" BorderColor="#DEBA84" ClientIDMode="Static"
                    EmptyDataText="No Records Found!" EmptyDataRowStyle-ForeColor="Red" EmptyDataRowStyle-CssClass ="gvEmpty" >
                    <%--<HeaderStyle ForeColor="White" Font-Bold="True" BackColor="#428bca"></HeaderStyle>--%>
                    <%--<RowStyle BackColor="Gainsboro" />
                    <AlternatingRowStyle BackColor="White" />
                    <HeaderStyle BackColor="#0083C1" ForeColor="White"/>--%>
    
                    <RowStyle BackColor="#F7F7DE" BorderStyle="Solid" BorderWidth="1px" BorderColor="Black" />
                    <FooterStyle BackColor="#CCCC99" />
                    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                    <SelectedRowStyle BackColor="#CE5D5A" ForeColor="White" Font-Bold="True" />
                    <%--<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" BorderStyle="Solid" BorderWidth="1px" BorderColor="Black" />--%>
                    <HeaderStyle BackColor="#0083C1" ForeColor="White" Font-Bold="True" HorizontalAlign="Center"/>
                    <AlternatingRowStyle BackColor="White" BorderStyle="Solid" BorderWidth="1px" BorderColor="Black" />
    
                    <Columns>
                        <asp:templatefield headertext="Action">
                            <itemtemplate>
                                <asp:linkbutton id="btnedit"  tooltip="update record" CommandName="EditRow" causesvalidation="false" runat="server" cssclass="clslnkbutton"/> 
                            </itemtemplate>
                        </asp:templatefield>
    
                        <asp:templatefield headertext="Emp.Code">
                            <itemtemplate>
                                <asp:label runat="server" id="lblcode" text='<%#Eval("EmployeeId") %>'></asp:label>
                            </itemtemplate>
                        </asp:templatefield>
                        <asp:templatefield headertext="Name">
                            <itemtemplate>
                                <asp:label runat="server" id="lblFullName" text='<%#Eval("FullName") %>'></asp:label>
                            </itemtemplate>
                        </asp:templatefield>
                        <asp:templatefield headertext="Email">
                            <itemtemplate>
                                <asp:label runat="server" id="lblEmail" text='<%#Eval("Email") %>'></asp:label>
                            </itemtemplate>
                        </asp:templatefield>
                        
                            <ItemTemplate>
    
                                <asp:Button ID="Button1" runat="server" Text=" History" CommandName='<%#Eval("EmployeeId") %>' CommandArgument='<%#  
                                    Container.DataItemIndex%>' />
                                
                                    <asp:GridView ID="gvwDetails" runat="server" AutoGenerateColumns="false"  CssClass="table table-bordered table-striped">
                                        <Columns>
                                            <asp:TemplateField HeaderText="EmployeeId" Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblEmployeeIdChild" Text='<%# Eval("EmployeeId") %>' runat="server"></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField ItemStyle-Width="100px" HeaderText="Amount">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblAmountChild" runat="server" Text='<%# Eval("BaseAmount")%>'></asp:Label>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtAmount_Child" runat="server" Text='<%# Bind("BaseAmount")%>'></asp:TextBox>
                                                </EditItemTemplate>
                                            </asp:TemplateField>
                                            
    
                                            <asp:ButtonField CommandName="Delete" Text="Delete" />
    
                                        </Columns>
                                    </asp:GridView>
    
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                    </Columns>
                    </asp:GridView>

    Thanks

    Tuesday, November 13, 2018 10:54 AM
  • User-1716253493 posted

    Convert the commandfield to templatefield, then set the delete button onclientclick property

    OnClientClick="return confirm('Are you sure?');"

    Wednesday, November 14, 2018 1:29 AM
  • User839733648 posted

    Hi JagjitSingh,

    You could find your delete control and then use .Attributes.Add() to add a confirm information to it.

    You could add following codes in your RowDataBound() event.

    LinkButton delbtn =   e.Row.Cells[2].Controls[0] as LinkButton;
    delbtn.Attributes.Add("onclick","return confirm('Are you sure you want to delete?');");

    For more about this, you could refer to the link: Building a delete confirm in a GridView control

    Best Regards,

    Jenifer

    Wednesday, November 14, 2018 6:42 AM