我在ASP.NET页面中有一个Wizard
控件。我正在尝试提供回个人WizardStep
的链接。我找不到任何关于这样做的信息。
这是一些帮助可视化我的问题的代码
<asp:Wizard runat="server" ID="Wizard">
<HeaderTemplate>
<ul>
<li><a href="<%=LinkToTheFirstStep %>">Step 1</a></li>
<li><a href="<%=LinkToTheSecondStep %>">Step 2</a></li>
</ul>
</HeaderTemplate>
<WizardSteps>
<WizardSteps runat="server" ID="WizardStepPersonal">
</WizardSteps>
<WizardSteps runat="server" ID="WizardStepTravel">
</WizardSteps>
</WizardSteps>
</asp:Wizard>
答案 0 :(得分:2)
你可以只有一个查询字符串变量,比如?step = 1并在页面加载时检查它,然后将你的向导设置为:
Wizard.ActiveStepIndex = int.Parse(Request["step"]);
当然还有一点错误检查。
编辑:对不起,ActiveStepIndex接受和int,我最初试图将字符串转换为int。
答案 1 :(得分:0)
您可以使用asp:Menu
页面
<asp:Menu ID="MyWizardMenu" Orientation="Horizontal" OnMenuItemClick="MyWizardMenu_MenuItemClick" runat="server">
<Items>
<asp:MenuItem Text="One" Selected="true" Value="0"></asp:MenuItem>
<asp:MenuItem Text="Two" Value="1" ></asp:MenuItem>
<asp:MenuItem Text="Three" Value="2"></asp:MenuItem>
</Items>
</asp:Menu>
<asp:Wizard ID="MyWizard" runat="server" OnNextButtonClick="MyWizard_NextButtonClick" OnPreviousButtonClick="MyWizard_PreviousButtonClick" DisplaySideBar="false">
<WizardSteps>
<asp:WizardStep ID="one" Title="One" runat="server">One</asp:WizardStep>
<asp:WizardStep ID="two" Title="Two" runat="server">Two</asp:WizardStep>
<asp:WizardStep ID="three" Title="Three" runat="server">Three</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
背后的代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MyWizard.ActiveStepIndex = 0;
}
}
protected void MyWizardMenu_MenuItemClick(object sender, MenuEventArgs e)
{
int index = Int32.Parse(e.Item.Value);
MyWizard.ActiveStepIndex = index;
}
protected void MyWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
MyWizardMenu.Items[e.NextStepIndex].Selected = true;
}
protected void MyWizard_PreviousButtonClick(object sender, WizardNavigationEventArgs e)
{
MyWizardMenu.Items[e.CurrentStepIndex - 1].Selected = true;
}
甚至可以将MyWizard.WizardSteps
绑定到MyWizardMenu.DataSource
(以避免将您的步骤硬编码到导航项)但是我还没有这样做,因为仅仅转换为IHierachicalEnumaration是不够的。