显示多视图控件的所有视图 [英] Show all views of multiview control
问题描述
我在多视图控件中有一个包含3个视图的ASP.NET页面。有没有办法在单个页面上显示所有视图以保存?我想避免用户将每个视图保存为单独的页面。我正在使用.NET 4.
我尝试过:
我已经找到了解决方案,但没有找到令人满意的结果。关于视图状态有一些讨论,但我不明白如何使用它来实现我的目标。
I have an ASP.NET page with 3 views in a multiview control. Is there a way to show all the views on a single page to save? I want to avoid users having to save each view as a separate page. I'm using .NET 4.
What I have tried:
I have searched for a solution, but find nothing satisfactory. There is some discussion on view state, but I don't understand how to use this to accomplish my objective.
推荐答案
如文档中所述,它不支持此。
As stated in the documentation it does not support this.
一次只能将一个View控件定义为在MultiView控件中处于活动状态。设置为ActiveViewIndex属性的View控件将呈现给客户端。如果将ActiveViewIndex属性设置为MultiView控件中不存在的View,则会在运行时引发ArgumentOutOfRangeException。如果属性为空,则MultiView控件不会向客户端呈现任何内容。
Only one View control at a time can be defined as active within a MultiView control. The View control that is set to the ActiveViewIndex property will be rendered to the client. If the ActiveViewIndex property is set to a View that does not exist within the MultiView control, a ArgumentOutOfRangeException is raised at run time. If the property is empty, the MultiView control does not render any content to the client.
I would really like to understand the motivation for needing to show all views at the same time . Normally the views are mutually exclusive and thus you only see one at a time. If for you there is a scenario that requires showing all views simultaneously then maybe you should be using panels with hide/show on navigation and the possibility to 'Show all'. I have some code below which shows you how to achieve this in views but I would not recommend it and ideally ask you to change your design for incorporating this scenario. Anyways here goes...
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack && MultiView1.ActiveViewIndex == MultiView1.Views.Count - 1)
{
if (MultiView1.Views[MultiView1.ActiveViewIndex].Controls.Count == 1)
{
HydrateView();
}
}
}
private void HydrateView()
{
int k = 0;
for (int i = 0; i < MultiView1.Views.Count - 1; i++)
{
View x = (View)MultiView1.Views[i];
for (int j = 0; j < x.Controls.Count; j++)
{
Control c = x.Controls[j] as Panel;
if (c != null)
{
MultiView1.Views[MultiView1.ActiveViewIndex].Controls.AddAt(k, c);
k++;
}
}
}
}
protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
{
if (MultiView1.ActiveViewIndex == MultiView1.Views.Count-1) {
HydrateView();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = MultiView1.ActiveViewIndex - 1;
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = MultiView1.ActiveViewIndex +1;
}
protected void Button4_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = MultiView1.Views.Count - 1;
}
<asp:MultiView ID="MultiView1" runat="server" OnActiveViewChanged="MultiView1_ActiveViewChanged" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></asp:Panel>
<asp:Button ID="Button2" runat="server" Text="Next" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="Show All" OnClick="Button4_Click" /></asp:View>
<asp:View ID="View2" runat="server">
<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Item1</asp:ListItem>
<asp:ListItem>Item2</asp:ListItem>
<asp:ListItem>Item3</asp:ListItem>
</asp:DropDownList>
</asp:Panel>
<asp:Button ID="Button4" runat="server" Text="Previous" OnClick="Button3_Click" />
<asp:Button ID="Button5" runat="server" Text="Show All" OnClick="Button4_Click" /></asp:View>
<asp:View ID="AllView" runat="server">
</asp:View>
</asp:MultiView>
这篇关于显示多视图控件的所有视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!