我正在寻找一些添加行按钮的帮助,我在插入数据时遇到问题。
这是我收到的错误: Error1:方法'受保护的Sub SqlDataSource2_Inserting(sender As Object,e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs)'无法处理事件'Public Event Inserting(sender As Object,e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)'因为他们没有兼容的签名。 C:\ Users \ Administrator \ Documents \ Visual Studio 2012 \ Projects \ Certificates \ Certificates \ WebForm1.aspx.vb 17 161证书
html代码:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Certificates.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<br />
<br />
<asp:GridView ID="Laboratory" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="LaboratoryID" DataSourceID="SqlDataSource2" ShowFooter="True">
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="AddRow" runat="server" CommandName="Insert" Text="Add" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Providence" SortExpression="Providence">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Providence") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtProvidence" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Providence") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City" SortExpression="City">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtCity" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ZipCode" SortExpression="ZipCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("ZipCode") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtZipCode" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("ZipCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country" SortExpression="Country">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Country") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtCountry" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Country") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone" SortExpression="Phone">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtPhone" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fax" SortExpression="Fax">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("Fax") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtFax" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Fax") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GreatGrizzlyConnectionString1 %>" DeleteCommand="DELETE FROM [Laboratory] WHERE [LaboratoryID] = @LaboratoryID" InsertCommand="INSERT INTO [Laboratory] ([Name], [Address], [Providence], [City], [ZipCode], [Country], [Phone], [Fax], [Email]) VALUES (@Name, @Address, @Providence, @City, @ZipCode, @Country, @Phone, @Fax, @Email)" SelectCommand="SELECT * FROM [Laboratory]" UpdateCommand="UPDATE [Laboratory] SET [Name] = @Name, [Address] = @Address, [Providence] = @Providence, [City] = @City, [ZipCode] = @ZipCode, [Country] = @Country, [Phone] = @Phone, [Fax] = @Fax, [Email] = @Email WHERE [LaboratoryID] = @LaboratoryID">
<DeleteParameters>
<asp:Parameter Name="LaboratoryID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Providence" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Providence" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="LaboratoryID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
这是我的vb代码:
公共类WebForm1 继承System.Web.UI.Page
受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load
End Sub
Private Sub GridView1_RowCommand(sender as Object,e As GridViewCommandEventArgs)处理Laboratory.RowCommand '如果CommandName ==“插入”,则插入数据 '和验证控件表示有效数据...... 如果e.CommandName =“Insert”AndAlso Page.IsValid Then '插入新纪录...... SqlDataSource2.Insert() 万一 结束子
' Sub to reference footer text cells and Insert them into new row in database
受保护的Sub SqlDataSource2_Inserting(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs)处理SqlDataSource2.Inserting '以编程方式引用插入界面中的Web控件... Dim NewName As TextBox = Laboratory.FooterRow.FindControl(“txtName”) Dim NewAddress As TextBox = Laboratory.FooterRow.FindControl(“txtAddress”) Dim NewProvidence As TextBox = Laboratory.FooterRow.FindControl(“txtProvidence”) Dim NewCity As TextBox = Laboratory.FooterRow.FindControl(“txtCity”) Dim NewZipCode As TextBox = Laboratory.FooterRow.FindControl(“txtZipCode”) Dim NewCountry As TextBox = Laboratory.FooterRow.FindControl(“txtcountry”) Dim NewPhone As TextBox = Laboratory.FooterRow.FindControl(“txtPhone”) Dim NewFax As TextBox = Laboratory.FooterRow.FindControl(“txtFax”) Dim NewEmail As TextBox = Laboratory.FooterRow.FindControl(“txtEmail”)
' Set the ObjectDataSource's InsertParameters values...
e.InputParameters("Name") = NewName.Text
e.InputParameters("Address") = NewAddress.Text
e.InputParameters("Providence") = NewProvidence.Text
e.InputParameters("City") = NewCity.Text
e.InputParameters("ZipCode") = NewZipCode.Text
e.InputParameters("Country") = NewCountry.Text
e.InputParameters("Phone") = NewPhone.Text
e.InputParameters("Fax") = NewFax.Text
e.InputParameters("Email") = NewEmail.Text
End Sub
受保护的子GridView1_SelectedIndexChanged(sender as Object,e As EventArgs)处理GridView1.SelectedIndexChanged
End Sub 结束班
答案 0 :(得分:0)