I am trying to follow this example from the web to create an insert command on my datagrid view control:
http://www.dotnetbips.com/articles/c1e0ca90-5f5d-47aa-a739-492b562e810a.aspxI think i have it all setup like he says. However when I go to insert it doesn't do anything. At the bottom of the window i see the following error:
Javascript:_doPostBack('Gr
idview1', 'Insert$3')
what does that mean?
my code behind looks like this:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
WebParts;
using System.Web.UI.HtmlControls
;
public partial class Contacts : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand(objec
t sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
GridView1.DataSourceID = "";
GridView1.DataBind();
}
}
protected void DetailsView1_ItemInserted(
object sender, DetailsViewInsertedEventAr
gs e)
{
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();
}
}
my asp form looks like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Contacts.aspx.cs
" Inherits="Contacts" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml"
>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestADNI
Connection
String %>"
DeleteCommand="DELETE FROM [ADNI Contacts] WHERE [Center] = @Center" InsertCommand="INSERT INTO [ADNI Contacts] ([Center], [Contact], [Address], [City], [State], [Zip Code], [Phone], [Fax], [Email], [Notes]) VALUES (@Center, @Contact, @Address, @City, @State, @Zip_Code, @Phone, @Fax, @Email, @Notes)"
SelectCommand="SELECT [Center], [Contact], [Address], [City], [State], [Zip Code] AS Zip_Code, [Phone], [Fax], [Email], [Notes] FROM [ADNI Contacts]"
UpdateCommand="UPDATE [ADNI Contacts] SET [Contact] = @Contact, [Address] = @Address, [City] = @City, [State] = @State, [Zip Code] = @Zip_Code, [Phone] = @Phone, [Fax] = @Fax, [Email] = @Email, [Notes] = @Notes WHERE [Center] = @Center">
<DeleteParameters>
<asp:Parameter Name="Center" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Contact" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
<asp:Parameter Name="Zip_Code" Type="Int32" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="Center" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Center" Type="String" />
<asp:Parameter Name="Contact" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
<asp:Parameter Name="Zip_Code" Type="Int32" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Notes" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False
"
DataKeyNames="Center" DataSourceID="SqlDataSourc
e1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="Center" HeaderText="Center" ReadOnly="True" SortExpression="Center" />
<asp:BoundField DataField="Contact" HeaderText="Contact" SortExpression="Contact" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="Zip_Code" HeaderText="Zip_Code" SortExpression="Zip_Code" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
<asp:ButtonField CommandName="Insert" Text="Insert" />
</Columns>
<EmptyDataTemplate>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4"
DataKeyNames="Center" DataSourceID="SqlDataSourc
e1" DefaultMode="Insert" ForeColor="#333333"
GridLines="None" Height="50px" Width="125px">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="Center" HeaderText="Center" ReadOnly="True" SortExpression="Center" />
<asp:BoundField DataField="Contact" HeaderText="Contact" SortExpression="Contact" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="Zip_Code" HeaderText="Zip_Code" SortExpression="Zip_Code" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
<FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>
</EmptyDataTemplate>
</asp:GridView>
</form>
</body>
</html>
Start Free Trial