タブ付きページ (4 つのタブ - タブ コンテナー) で作業しています。そのうちの 2 つは同じコントロールを使用し、アイテムを編集および追加できる異なるデータ ソースを持つ異なるグリッドビューを持っています。
アイテムの編集と追加は正常に機能しますが、アイテムを追加すると、新しいアイテムを表示するためにグリッドビューまたはページを更新する必要があります。Response.Redirect を使用すると、ページが更新されるだけで、最初のタブにリダイレクトされます。私はタブ 2 と 3 に取り組んでおり、リダイレクトは常に最初のタブではなく、関連するタブを指す必要があります。
これを行う方法について何か提案はありますか?
Visual Studio 2010、C# ASP.Net を使用しています
コード:
ページ:
<asp:Content ID="Content2" ContentPlaceHolderID="pnlMainContent" runat="server">
<div style="padding: 10px">
<cc1:TabContainer ID="tbMain" runat="server" ActiveTabIndex="0" Width="100%" AutoPostBack="true"
OnActiveTabChanged="tbMain_ActiveTabChanged">
<cc1:TabPanel runat="server" ID="tbpgWFTypes" HeaderText="Work Flow Types">
<ContentTemplate>
<table style="width: 100%">
<tr>
<td align="center">
<uc1:ctrlWorkflowTypeControl ID="ctrlWorkflowTypeControl" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel runat="server" ID="tbpgWFStatus" HeaderText="Work Flow Status">
<ContentTemplate>
<table style="width: 100%">
<tr>
<td align="center">
<uc2:ctrlStatusControl ID="ctrlStatusControl" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel runat="server" ID="tbpgWFActions" HeaderText="Work Flow Actions">
<ContentTemplate>
<table style="width: 100%">
<tr>
<td align="center">
<uc3:ctrlActionControl ID="ctrlActionControl" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel runat="server" ID="tbpgWFRouting" HeaderText="Work Flow Routing">
<ContentTemplate>
<table style="width: 100%">
<tr>
<td align="center">
<uc4:ctrlWorkflowRoutingControl ID="ctrlWorkflowRoutingControl" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
</div>
コードビハインド:
protected void Page_Load(object sender, EventArgs e)
{
tbpgWFTypes.Focus();
if (!IsPostBack)
{
tbMain_ActiveTabChanged(tbMain, null);
}
}
protected void tbMain_ActiveTabChanged(object sender, EventArgs e)
{
try
{
if (tbMain.ActiveTabIndex == 1)
{
ctrlActionControl.ActionPanelMode = true;
ctrlStatusControl.StatusPanelMode = false;
}
if (tbMain.ActiveTabIndex == 2)
{
ctrlStatusControl.StatusPanelMode = true;
ctrlActionControl.ActionPanelMode = false;
}
}
catch (Exception ex)
{
Support.ExceptionHandler.HandleException(ex);
}
}
}
コントロール:
<table>
<tr>
<td align="left" colspan="2">
<asp:DropDownList ID="ddlWFStatus" runat="server" Width="400px" DataSourceID="dsStatus" DataTextField="Description" Visible="false"></asp:DropDownList>
<asp:DropDownList ID="ddlWFAction" runat="server" Width="400px" DataSourceID="dsAction" DataTextField="Description" Visible="false"></asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td align="left" colspan="2">
<asp:Panel ID="pnlStatus" runat="server" Visible="false">
<asp:GridView ID="gvStatus" runat="server" DataSourceID="dsStatus"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="WFStatusID"
ForeColor="#333333" EnableSortingAndPagingCallbacks="True" AllowPaging="True"
AllowSorting="True" onselectedindexchanged="gvStatus_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="WFStatusID" HeaderText="WFStatusID" SortExpression="WFStatusID" Visible="false">
<ItemStyle HorizontalAlign="Left" Width="400px" />
</asp:BoundField>
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description">
<ItemStyle HorizontalAlign="Left" Width="400px" />
</asp:BoundField>
<asp:CommandField ButtonType="Button" EditText="Edit" ShowEditButton="true" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</asp:Panel>
<asp:Panel ID="pnlAction" runat="server" Visible="false">
<asp:GridView ID="gvAction" runat="server" DataSourceID="dsAction"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="WFActionID"
ForeColor="#333333" EnableSortingAndPagingCallbacks="True" AllowPaging="True"
AllowSorting="True" onselectedindexchanged="gvAction_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="WFActionID" HeaderText="WFActionID" SortExpression="WFActionID" Visible="false">
<ItemStyle HorizontalAlign="Left" Width="400px" />
</asp:BoundField>
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description">
<ItemStyle HorizontalAlign="Left" Width="400px" />
</asp:BoundField>
<asp:CommandField ButtonType="Button" EditText="Edit" ShowEditButton="true" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</asp:Panel>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<asp:Button ID="btnShowAddSection" runat="server" Text="" onclick="btnShowAddSection_Click"/>
</td>
</tr>
<tr id="divAddEditRow" runat="server" visible="false">
<td><asp:Label ID="lblAdd" runat="server" Text="New Item: " />
<asp:TextBox ID="txtEdit" runat="server" ></asp:TextBox>
</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" onclick="btnAdd_Click" style="float: right; padding-right:5px; margin-right:8px"/>
</td>
</tr>
</table>
<asp:ObjectDataSource ID="dsStatus" runat="server" SelectMethod="FillWFStatus" UpdateMethod="UpdateWFStatus"
TypeName="***.**.Services.WorkflowDataService" onupdating="dsStatus_Updating">
<UpdateParameters>
<asp:Parameter Type="Int32" Name="WFStatusID" />
<asp:Parameter Type="String" Name="Description" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="dsAction" runat="server" SelectMethod="FillWFAction" UpdateMethod="UpdateWFAction"
TypeName="***.**.Services.WorkflowDataService" onupdating="dsAction_Updating">
<UpdateParameters>
<asp:Parameter Type="Int32" Name="WFActionID" />
<asp:Parameter Type="String" Name="Description" />
</UpdateParameters>
</asp:ObjectDataSource>
制御コードの背後:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void gvStatus_SelectedIndexChanged(object sender, EventArgs e)
{
WorkflowDataService.InsertWFStatus(0, txtEdit.Text);
}
protected void gvAction_SelectedIndexChanged(object sender, EventArgs e)
{
WorkflowDataService.InsertWFAction(0, txtEdit.Text);
}
public bool StatusPanelMode
{
set { pnlStatus.Visible = !value;
btnShowAddSection.Text = "Add New Status";
ddlWFStatus.Visible = !value;
}
}
public bool ActionPanelMode
{
set
{
pnlAction.Visible = !value;
btnShowAddSection.Text = "Add New Action";
ddlWFAction.Visible = !value;
}
}
protected void btnShowAddSection_Click(object sender, EventArgs e)
{
this.divAddEditRow.Visible = true;
btnShowAddSection.Visible = false;
}
protected void dsStatus_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
var test = gvStatus.SelectedIndex;
var test2 = dsStatus.UpdateParameters[0];
}
protected void dsAction_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
var test = gvStatus.SelectedIndex;
var test2 = dsAction.UpdateParameters[0];
}
protected void btnAdd_Click(object sender, EventArgs e)
{
this.divAddEditRow.Visible = false;
btnShowAddSection.Visible = true;
if (pnlStatus.Visible == true)
{
WorkflowDataService.InsertWFStatus(0, txtEdit.Text);
//Response.Redirect("ManageRoutingPage.aspx?tab=2"); <--- This Doesnt Work
}
if (pnlAction.Visible == true)
{
WorkflowDataService.InsertWFAction( 0, txtEdit.Text);
Response.Redirect("ManageRoutingPage.aspx"); // <-- This goes back to tab 1 instead of 3
}
}
}