Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i have a problem with my syntax in RowDataBound. I Want to create deleteing row in gridview without database and then i find a problem in RowDataBound. please help me (sry bad english)

What I have tried:

In .aspx
ASP.NET
<pre><asp:GridView ID="gvPluPlano" runat="server" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="gvPluPlano_PageIndexChanging" OnRowDeleting="gvPluPlano_RowDeleting" EmptyDataText="No records has been added." PageSize="500" ShowHeaderWhenEmpty="True" AllowSorting="True" headerstyle-cssclass="FixedHeader" Width="850px" style="margin-top: 0px" >
                        <HeaderStyle BackColor="Black" ForeColor="White" />
                        <RowStyle BackColor="White" ForeColor="Black" Wrap="false" />
                        <AlternatingRowStyle BackColor="#e5e5e5" ForeColor="Black" />
                        <SelectedRowStyle BackColor="#999999" ForeColor="#fff" />
                        <Columns>
                            <asp:TemplateField HeaderText="PLU" HeaderStyle-CssClass="header-center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="150">
                                <ItemTemplate>
                                    <asp:Label ID="lblPlu" runat="server" Text='<%# Eval("NAMAPLU") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtPlu" runat="server" MaxLength="8" Text='<%# Eval("NAMAPLU") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="header-center"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Center" Width="100px"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Description PLU" HeaderStyle-CssClass="header-center" ItemStyle-Width="150">
                                <ItemTemplate>
                                    <asp:Label ID="lblDescriptionPlu" runat="server" Text='<%# Eval("DESKRIPSIPLU") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtDescriptionPlu" runat="server" MaxLength="100" Text='<%# Eval("DESKRIPSIPLU") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="header-center"></HeaderStyle>
                                <ItemStyle Width="200px"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField ShowHeader="False">
                                <ItemTemplate>
                                    <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return confirm('Are you sure you want to delete?'); " CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
                                </ItemTemplate>
                                <ItemStyle Width="50px" HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>


in .Vb
VB
Protected Sub gvPluPlano_RowDataBound(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim item As String = e.Row.Cells(0).Text
            For Each button As Button In e.Row.Cells(2).Controls.OfType(Of Button)()
                If button.CommandName = "Delete" Then
                    button.Attributes("onclick") = "if(!confirm('Do you want to delete " + item + "?')){ return false; };"
                End If
            Next
        End If
    End Sub

    Protected Sub gvPluPlano_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)
        Dim Index As String = txtPlu2.Text
        Dim dt As DataTable = TryCast(ViewState("dt"), DataTable)
        dt.Rows(Index).Delete()
        ViewState("dt") = dt
        LoadData()
    End Sub
Posted
Updated 16-Jul-20 0:25am

1 solution

You need to import the System.Linq namespace, which is defined in the System.Core assembly.
 
Share this answer
 
Comments
SDK Channel 17-Jul-20 1:18am    
I use a web form, when I type Imports System.Linq the system does not appear

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900