Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2011, 10:23 AM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default How to set Default Formview data on a Master/Details page?

Hello,

I have a page that uses a Master/Detail arrangement to display a series of links in a GridView and details from each link in a FormView control.

Several pages use this arrangement to display different data from the same table (i.e. the grade 3 page only displays grade 3-related table rows).

My problem is that the FormView control always displays data form the first row in the source table when the page is first loaded. If I wanted to force the FormView to display data from a different default row for a particular page, should I do that in code behind, or as part of a URL parameter?

For example, the grade 4 page should display an entry from the grade 4 rows, rather than the 1st table row (which is grade 1).

The aspx page code is as follows (there are no code behind event handlers yet):

Code:
    <form id="form1" runat="server">
    <table class="components">
                    <tr>
                        <td valign="top">
                            <asp:GridView 
                                ID="grdTeacherList" 
                                runat="server" 
                                AutoGenerateColumns="False" 
                                DataKeyNames="ProductID" 
                                DataSourceID="srcProductListTeacher" 
                                CssClass="componentcell"
                                GridLines="None">
                                <Columns>
                                    <asp:ButtonField 
                                        CommandName="Select" 
                                        ShowHeader="True" 
                                        HeaderText="Teacher Materials"
                                        HeaderStyle-HorizontalAlign="Left" 
                                        DataTextField="ProductName" >
                                    <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                                    </asp:ButtonField>
                                </Columns>
                            </asp:GridView>     
                        </td>
                        <td valign="top">
                            <asp:FormView 
                                             ID="fvTeacherDetails" 
                                             runat="server" 
                                             DataSourceID="srcProductDetailsTeacher" 
                                             Width="416px">
                                <ItemTemplate>
                                    <asp:Image ID="Image1"  ImageAlign="Right" runat="server" ImageUrl='<%# Eval("ImageFile",  "~/images/products/{0}") %>' CssClass="product_image" />
                                    <h2 class="producttitle" ><asp:Label ID="ProductNameLabel" runat="server"  
                                        Text='<%# Eval("ProductName") %>' /></h2>
                                    <p><asp:Label  ID="ProductTypeLabel" runat="server" Text='<%# Eval("ProductType")  %>' />
                                    <br />
                                    Grade
                                    <asp:Label ID="GradeLabel" runat="server" Text='<%# Eval("Grade") %>' />
                                    <br />
                                    ISBN:
                                    <asp:Label ID="ISBNLabel" runat="server" Text='<%# Eval("ISBN") %>' /></p>
                                    <p><asp:Label  ID="DescriptionLabel" runat="server" Text='<%# Bind("Description")  %>' /></p>
                                    <p>Item Number:
                                    <asp:Label ID="ProductSKULabel"  runat="server" Text='<%# Eval("ProductSKU") %>' />
                                    <br />
                                    Price:
                                    <asp:Label ID="PriceLabel"  runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Price",  "{0:c}") %>' /></p>
                                </ItemTemplate>
                            </asp:FormView>
                        </td>
                    </tr>
                </table> 
                <asp:SqlDataSource 
                    ID="srcProductListTeacher" 
                    runat="server" 
                    ConnectionString="<%$ ConnectionStrings:mathConnectionString %>" 
                    SelectCommand="SELECT [ProductID], [ProductName]  FROM [Products] WHERE (([Grade] = @Grade) AND ([ProductTypeIndex] =  @ProductTypeIndex))">
                    <SelectParameters>
                        <asp:Parameter DefaultValue="4" Name="Grade" Type="String" />
                        <asp:Parameter DefaultValue="1" Name="ProductTypeIndex" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>  
                <asp:SqlDataSource ID="srcProductDetailsTeacher" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:mathConnectionString %>" 
                    SelectCommand="SELECT [ProductName], [ProductSKU],  [ProductID], [ProductType], [ImageFile], [Grade], [ISBN], [Description],  [Price] FROM [Products] WHERE ([ProductID] = @ProductID)">
                    <SelectParameters>
                        <asp:ControlParameter 
                            ControlID="grdTeacherList" 
                            Name="ProductID" 
                            PropertyName="SelectedValue" 
                            Type="Int32" 
                            DefaultValue="12"/>
                    </SelectParameters>
                </asp:SqlDataSource>     
                
    </form>
Thanks for any advice.
 
Old June 24th, 2011, 05:20 PM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default

OK, I have it -

I had unwittingly set the DefaultValue to a specific row ID and hadn't realized it:

Code:
                   <SelectParameters>
                       <asp:ControlParameter 
                            ControlID="grdTeacherList" 
                            Name="ProductID" 
                            PropertyName="SelectedValue" 
                            Type="Int32" 
                            DefaultValue="12"/>
                    </SelectParameters>
Nevermind!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Set default FormView contents in Master details page? Nostromo77 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 June 23rd, 2011 10:25 AM
Master/Details display: can two Master lists feed the same Details control? Nostromo77 BOOK: Professional ASP.NET 3.5 SP1 Edition: In C# and VB 1 July 2nd, 2010 03:00 PM
set the default page as login ramkiran ASP.NET 2.0 Basics 1 April 22nd, 2007 10:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.