最初に私のhtml
<asp:GridView ID="GridViewCustomers" runat="server" AutoGenerateColumns="False"
AllowPaging="True" datakeynames="Reservation_ID,Excursion_ID"
onpageindexchanging="GridViewCustomers_PageIndexChanging"
onrowcommand="GridViewCustomers_SelectedIndexChanged"
BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" >
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Reservation_ID" HeaderText="РЕЗ. №" />
<asp:BoundField DataField="Name" HeaderText="Име на Екскурзия" />
<asp:BoundField DataField="Reservation_TotalAmount" HeaderText="Сума по резервацията" />
<asp:BoundField DataField="Excursion_ID" Visible="false" />
<asp:BoundField DataField="ReservationDate" HeaderText="Дата на заминаване" />
<asp:TemplateField HeaderText="Имена на Туристи">
<ItemTemplate>
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("TouristName") %>'>
<ItemTemplate>
<%# (Container.ItemIndex+1)+"."+ Container.DataItem %><br />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
したがって、コードでは、選択ボタンをクリックすると、datakeyna の値を取得し、ユーザーを別のページにリダイレクトすることがわかります。問題は、グリッドビューのページ 2 をクリックすると、1 つの行を選択したかのように他のページにリダイレクトされることです。
protected void Page_Init(object sender, EventArgs e)
{
this.lstUserReservations.AddRange(lstUserReservations);
this.lstUserReservations.AddRange(lstUserReservations);
this.lstUserReservations.AddRange(lstUserReservations);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
User_Reservation trr = new User_Reservation();
lstUserReservations = new List<User_Reservation>();
lstUserReservations = LoadReservationsForUser();
GridViewCustomers.DataSource = lstUserReservations;
GridViewCustomers.DataBind();
}
}
protected void GridViewCustomers_SelectedIndexChanged(object sender, GridViewCommandEventArgs e)
{ int indexer = Int32.Parse(e.CommandArgument.ToString());
Session["еxcursion_id"] = this.GridViewCustomers.DataKeys[indexer].Values["Excursion_ID"].ToString();
Response.Redirect("ReservationInfo.aspx");
}
protected void GridViewCustomers_PageIndexChanging(object sender,
System.Web.UI.WebControls.GridViewPageEventArgs e)
{
this.GridViewCustomers.PageIndex = e.NewPageIndex;
this.GridViewCustomers.DataBind();
}
}
私が持っていることがわかります