插入后的消息
我有一个简单的输入表单,想在用户插入数据后包含一条感谢消息。我的 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>");
}
}
i have a simple input form, want to include a thank you message after a user inserts a data. my OnInserting="SqlDataSource1_Inserted"
method is not working. i'm new to programming so no judgment :/
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 %>"
Markup:
<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>
Code-behind:
protected void SqlDataSource1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.AffectedRows > 0)
{
Response.Write("<script language='javascript'> { alert('a message');}</script>");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它可能是您需要的 OnInserted 事件,而不是 OnInserting (在您的 aspx 中)。
这是插入后提出的。
涡轮
It'll probably be the OnInserted event that you need, not OnInserting (in your aspx).
This is raised post Insert.
Turbo
删除响应消息中的大括号,如下所示
Remove curly brackets on your response message as
@MG,
您需要处理 Inserted 事件,但看看您的代码,它是 inserting
@MG,
You need to handle Inserted event but look at your code, it is inserting