我正在尝试在窗体 View 上成功插入命令后进行重定向。这是我拥有的:
细节.aspx:
<asp:FormView id="formview1"...datasourceid="detailsSQLDS">
<InsertItemTemplate>
DateOfService:
<asp:TextBox ID="DateOfServiceTextBox" runat="server"
Text='<%# Bind("DateOfService") %>' />
<br />
InsurancePrimary:
<asp:TextBox ID="InsurancePrimaryTextBox" runat="server"
Text='<%# Bind("InsurancePrimary") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
</InsertItemTemplate>
</asp:FOrmView>
....
<asp:SqlDataSource ID="detailsSQLDS" runat="server"
ConnectionString="..."
InsertCommandType="StoredProcedure"
InsertCommand="usp_Insert"
>
代码隐藏:
protected void formview1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
Response.Redirect( "List.aspx?mrn=" + Request.QueryString["mrn"] );
}
插入工作正常,但不是重定向。我认为它不会触发函数 formview1_ItemInserted(....)。有没有办法告诉 formview 在成功插入后触发此功能,或以其他方式执行此操作?谢谢!
最佳答案
啊,我找到了。我需要将 OnItemInserted="formview1_ItemInserted"声明添加到我的窗体 View 中。所以我有:
<asp:FormView id="formview1"...datasourceid="detailsSQLDS" OnItemInserted="formview1_Item_Inserted">
现在效果很好。
关于asp.net - 在 formview 插入命令后重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13163312/