我有一个简单的输入表单,想在用户插入数据后包含一条感谢信息。我的OnInserting="SqlDataSource1_Inserted"
方法无效。我是编程的新手所以没有判断力:/
error message:
CS0123: No overload for 'SqlDataSource1_Inserted' matches delegate 'System.Web.UI.WebControls.SqlDataSourceCommandEventHandler'
Line 36: </p>
Line 37: <p>
Line 38: <asp:SqlDataSource ID="SqlDataSource1" runat="server"
Line 39: ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>"
标记:
<body>
<form id="form1" runat="server">
<p>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" Height="50px"
DefaultMode="Insert" CellPadding="4"
GridLines="None">
<Fields>
<asp:BoundField DataField="email" HeaderText="text_test" SortExpression="text_test" />
<asp:CommandField ShowInsertButton="True"/>
</Fields>
</asp:DetailsView>
</p>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:VZConnectionString %>"
InsertCommand="INSERT INTO [test] ([text_test]) VALUES (@text_test)"
OnInserting="SqlDataSource1_Inserted"
ProviderName="<%$ ConnectionStrings:TESTConnectionString.ProviderName %>"
SelectCommand="SELECT text_test FROM test" >
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="text_test" />
</InsertParameters>
</asp:SqlDataSource>
</p>
</form>
</body>
</html>
代码隐藏:
protected void SqlDataSource1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.AffectedRows > 0)
{
Response.Write("<script language='javascript'> { alert('a message');}</script>");
}
}
答案 0 :(得分:2)
它可能是您需要的OnInserted事件,而不是OnInserting(在您的aspx中)。
这是在插入后引发的。
涡轮
答案 1 :(得分:1)
删除回复消息上的大括号
Response.Write("<script language='javascript'> alert('a message');</script>");
答案 2 :(得分:1)
@MG,
您需要处理已插入事件,但请查看您的代码,插入
...
oninserted="SqlDataSource1_Inserted"
..