0

我正在处理一个选项卡式页面(4 个选项卡 - 选项卡容器),其中 2 个使用相同的控件并具有不同的 gridview 和不同的数据源,可以编辑和添加项目。

编辑和添加项目工作正常,但是当我添加项目时,gridview 或页面需要刷新以显示新项目。使用 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
    }
  }            
}    
4

1 回答 1

4

您可以为此目的使用查询字符串,如下所示

Response.Redirect("default.aspx?tab=1");
Response.Redirect("default.aspx?tab=2");
Response.Redirect("default.aspx?tab=3");

并在default.aspx 页面中。你可以做类似的事情

var tab = Request.QueryString["tab"];
switch(tab)
{
case "1":
//Bind data for first tab
break;
case "2":
//Bind data for second tab
break;
}

希望能帮助到你 :)

于 2012-07-16T13:23:43.813 回答