'Oftype' не является членом 'controlcollection' в веб - формах
Здравствуйте, у меня проблема с синтаксисом в RowDataBound. Я хочу создать удаляющую строку в gridview без базы данных, а затем я нахожу проблему в RowDataBound. пожалуйста, помогите мне (sry bad english)
Что я уже пробовал:
В .aspx-файл
<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>
в .ВБ
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