ConsumerListページにgridViewがあります。[編集]ボタン(各行)をクリックすると、EditConsumerページに移動します。EditConsumerページで、Page.PreviousPageを使用して選択した行の値を取得する必要があります。これらの値を取得する方法は?
public void Consumer_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "CustomEdit")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
string consumerID = grdConsumers.Rows[rowIndex].Cells[1].Text;
string consumerName = grdConsumers.Rows[rowIndex].Cells[2].Text;
string consumerUrl = grdConsumers.Rows[rowIndex].Cells[3].Text;
string consumerStatus = grdConsumers.Rows[rowIndex].Cells[4].Text;
Response.Redirect("EditConsumer.aspx?RowIndex=" + rowIndex);
}
}
マークアップ
<asp:GridView ID="grdConsumers" runat="server" AutoGenerateColumns="False" CssClass="resultGridTable"
GridLines="None" EnableViewState="True" AllowSorting="True" OnSorting="Consumers_Sorting" OnRowCommand="Consumer_RowCommand">
<AlternatingRowStyle BackColor="#E5E5E5" />
<Columns>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:Button ID="btnView" runat="server" CssClass="actionButtonView"
Text="VIEW" Style="width: 40px" BackColor="Orange"
Font-Bold="True" ForeColor="White" />
<asp:Button ID="btnEdit" runat="server" CommandName="CustomEdit" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>"
CssClass="actionButtonEdit"
Text="EDIT" Style="width: 35px" BackColor="Orange"
Font-Bold="True" ForeColor="White" />
<asp:Button ID="btnDelete" runat="server" CssClass="actionButtonDelete"
Text="DELETE" Style="width: 55px" BackColor="Orange"
Font-Bold="True" ForeColor="White" />
<asp:Button ID="btnPing" runat="server" CssClass="actionButtonPing"
Text="PING" Style="width: 35px" BackColor="Orange"
Font-Bold="True" ForeColor="White" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Consumer ID" DataField="ConsumerID" SortExpression="ConsumerID"></asp:BoundField>
<asp:BoundField HeaderText="Consumer Name" DataField="ConsumerName" SortExpression="ConsumerName"></asp:BoundField>
<asp:BoundField HeaderText="Consumer URL" DataField="ConsumerURL" SortExpression="ConsumerURL"></asp:BoundField>
<asp:BoundField HeaderText="Status" DataField="Status" SortExpression="Status"></asp:BoundField>
</Columns>
</asp:GridView>