WEBSWAPP Silverlight ASP.NET 3.5 ASP.NET 2.0 ASP.NET 1.0
Cascading Lists
ITemplate
DDL in GridView
G/V MultiSelect
Nested GridViews
RegExp
DataGrid Reorder
Events fire twice
Hyperlink Field
TextBox
UpdateParameters
MultiView
TreeView
MultiView
    
<%@ Page Language="C#" MasterPageFile="~/Categories/WEBSWAPP.Master" AutoEventWireup="true" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { MultiView1.SetActiveView(View1); } View2.Load += new EventHandler(View2_Load); } void View2_Load(object sender, EventArgs e) { if (gvAddresses.SortExpression != null) { FormView1.DataBind(); } } protected void btnViewList_Command(object sender, CommandEventArgs e) { MultiView1.SetActiveView(View1); } protected void gvAddresses_SelectedIndexChanged(object sender, EventArgs e) { FormView1.PageIndex = (gvAddresses.PageSize * gvAddresses.PageIndex) + gvAddresses.SelectedIndex; MultiView1.SetActiveView(View2); } </script> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <asp:ObjectDataSource ID="odsAddresses" runat="server" SelectMethod="Contacts" TypeName="WEBSWAPP_BLL.Demos"> </asp:ObjectDataSource> <h3> MultiView demo - View Load event handling</h3> <asp:MultiView ID="MultiView1" runat="server"> <asp:View ID="View1" runat='server'> <asp:GridView ID="gvAddresses" runat="server" DataSourceID="odsAddresses" AllowPaging="True" AutoGenerateColumns='false' DataKeyNames="PK_ID" AllowSorting="true" OnSelectedIndexChanged="gvAddresses_SelectedIndexChanged"> <SelectedRowStyle BackColor="Gold" /> <EmptyDataTemplate> No Data is available </EmptyDataTemplate> <Columns> <asp:TemplateField HeaderText="Commands"> <ItemTemplate> <asp:LinkButton CommandName="Select" ID="btnSelect" runat="server" Text="View Detail"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Company Name" SortExpression="Company"> <ItemTemplate> <asp:Label ID="lblCompany" runat="server" Text='<%# Eval("Company") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Street Address"> <ItemTemplate> <asp:Label ID="lblStreet" runat="server" Text='<%# Eval("Street") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Country" SortExpression="Country"> <ItemTemplate> <asp:Label ID="lblCountry" runat="server" Text='<%#Eval("Country") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Province" SortExpression="Province"> <ItemTemplate> <asp:Label ID="lblProvince" runat="server" Text='<%#Eval ("Province") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="City" SortExpression="City"> <ItemTemplate> <asp:Label ID="lblCity" runat="server" Text='<%#Eval("City") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </asp:View> <asp:View ID="View2" runat="server"> <asp:FormView ID="FormView1" runat="server" DataSourceID="odsAddresses" AllowPaging="True" DataKeyNames="PK_ID"> <ItemTemplate> <table class="FormViewStyle1"> <caption style="color: Black; background-color: gainsboro;"> FormView in ReadOnly mode</caption> <tr> <td> Company </td> <td> <asp:Label ID="lblCompany" runat="server" Text='<%# Eval("Company") %>'></asp:Label> </td> </tr> <tr> <td> Street Address </td> <td> <asp:Label ID="lblStreet" runat="server" Text='<%# Eval("Street") %>'></asp:Label> </td> </tr> <tr> <td> Country </td> <td> <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>'></asp:Label> </td> </tr> <tr> <td> Province/State </td> <td> <asp:Label ID="lblProvince" runat="server" Text='<%# Eval("Province") %>'></asp:Label> </td> </tr> <tr> <td> City </td> <td> <asp:Label ID="lblCity" runat="server" Text='<%# Eval("City") %>'></asp:Label> </td> </tr> </table> </ItemTemplate> </asp:FormView> <asp:Button ID="btnViewList" runat="server" Text="ViewList" OnCommand="btnViewList_Command" /> </asp:View> </asp:MultiView> <p> The MultiView control renders only the content of the active view. If you perform an operation on the active view that you expect to affect one of the non-active views then you need to force the rendering of that change by handling the View.Load event. </p> <p> In this demo I have 2 views, one is GridView and the other is a FormView displaying the details of the selected record on the GridView. The FormView display is in a non-active view of a multiview control. When you click on the "View Detail" hyperlink, the View that contains the FormView is activated. Since both the FormView and GridView are attached to the same datasource, the active record on the FormView would appear in a pageIndex that corresponds to the rowindex on the GridView. However, when the GridView is sorted the FormView would not be sorted accordingly because the containing view has not been rendered and therefore it has not been databound to the sorted datasource. This can be solved by databinding the FormView during the View.Load event handling. </p> </asp:Content>