У меня есть две страницы: первая - это сетка, привязанная к DataSet, вторая - DetailsView, привязанная к DataSet, которая используется для редактирования и вставки.
После вставки на страницу DetailsView я хочуперенаправить на страницу GridView.
if (Request.QueryString["Id"] == null)
{
//prevPage = Request.UrlReferrer.ToString();
if (!IsPostBack)
{
DetailsView1.ChangeMode(DetailsViewMode.Insert);
}
Страница сведений позволяет правильно вставить новую запись, но после сохранения возвращает пустую страницу;как получить возврат на обновленную страницу сетки?
Я пытался использовать событие ItemInserted в DetailsView, но оно просто не запускается.
Обновление:
как предложено, я добавляю следующий код:
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
Response.Redirect("ms_Ticket.aspx");
}
(с ms_Ticket - страница просмотра сетки), но вставка продолжает возвращать пустое подробное представление.
Обновление:
здеськод за страницей сведений:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Rise_cs.Ticket
{
public partial class WebForm4 : System.Web.UI.Page
{
static string prevPage = String.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!(Request.UrlReferrer == null))
{
prevPage = Request.UrlReferrer.ToString();
}
}
if (Request.QueryString["Id"] == null)
{
//prevPage = Request.UrlReferrer.ToString();
if (!IsPostBack)
{
DetailsView1.ChangeMode(DetailsViewMode.Insert);
}
}
}
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
Response.Redirect("ms_Ticket.aspx");
}
}
}
вот дизайн:
//------------------------------------------------------------------------------
// <generato automaticamente>
// Codice generato da uno strumento.
//
// Le modifiche a questo file possono causare un comportamento non corretto e verranno perse se
// il codice viene rigenerato.
// </generato automaticamente>
//------------------------------------------------------------------------------
namespace Rise_cs.Ticket {
public partial class WebForm4 {
/// <summary>
/// Controllo DetailsView1.
/// </summary>
/// <remarks>
/// Campo generato automaticamente.
/// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
/// </remarks>
protected global::System.Web.UI.WebControls.DetailsView DetailsView1;
/// <summary>
/// Controllo SqlDataSource1.
/// </summary>
/// <remarks>
/// Campo generato automaticamente.
/// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
/// </remarks>
protected global::System.Web.UI.WebControls.SqlDataSource SqlDataSource1;
}
}
Обновление:
вот полный код формы:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="dt_TicketRiga.aspx.cs" Inherits="Rise_cs.Ticket.WebForm4" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="Id" DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:TemplateField HeaderText="TicketId" SortExpression="TicketId">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TicketId") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="Label3" runat="server"
Text='<%# Request.QueryString["TicketId"] %>'></asp:Label>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("TicketId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Data" HeaderText="Data" SortExpression="Data" />
<asp:BoundField DataField="Ora" HeaderText="Ora" SortExpression="Ora" />
<asp:BoundField DataField="OperatoreId" HeaderText="OperatoreId"
SortExpression="OperatoreId" />
<asp:BoundField DataField="Referente" HeaderText="Referente"
SortExpression="Referente" />
<asp:BoundField DataField="ModalitaContattoId" HeaderText="ModalitaContattoId"
SortExpression="ModalitaContattoId" />
<asp:BoundField DataField="Descrizione" HeaderText="Descrizione"
SortExpression="Descrizione" />
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Aggiorna"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Annulla"></asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Insert" onclick="LinkButton1_Click" Text="Inserisci"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Annulla"></asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Modifica"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="New" Text="Nuovo"></asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False"
CommandName="Delete" Text="Elimina"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:GONGConnectionString1 %>"
DeleteCommand="DELETE FROM [TicketRighe] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [TicketRighe] ([TicketId], [Data], [Ora], [OperatoreId], [Referente], [ModalitaContattoId], [Descrizione]) VALUES (@TicketId, @Data, @Ora, @OperatoreId, @Referente, @ModalitaContattoId, @Descrizione)"
SelectCommand="SELECT * FROM [TicketRighe] WHERE (([Id] = @Id) AND ([TicketId] = @TicketId))"
UpdateCommand="UPDATE [TicketRighe] SET [TicketId] = @TicketId, [Data] = @Data, [Ora] = @Ora, [OperatoreId] = @OperatoreId, [Referente] = @Referente, [ModalitaContattoId] = @ModalitaContattoId, [Descrizione] = @Descrizione WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:QueryStringParameter Name="TicketId" QueryStringField="TicketId"
Type="Int32" />
<asp:Parameter Name="Data" Type="DateTime" />
<asp:Parameter Name="Ora" Type="DateTime" />
<asp:Parameter Name="OperatoreId" Type="Int32" />
<asp:Parameter Name="Referente" Type="String" />
<asp:Parameter Name="ModalitaContattoId" Type="Int32" />
<asp:Parameter Name="Descrizione" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />
<asp:QueryStringParameter Name="TicketId" QueryStringField="TicketId"
Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="TicketId" Type="Int32" />
<asp:Parameter Name="Data" Type="DateTime" />
<asp:Parameter Name="Ora" Type="DateTime" />
<asp:Parameter Name="OperatoreId" Type="Int32" />
<asp:Parameter Name="Referente" Type="String" />
<asp:Parameter Name="ModalitaContattoId" Type="Int32" />
<asp:Parameter Name="Descrizione" Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>