Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 22nd, 2011, 11:55 AM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default Set default FormView contents in 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 22nd, 2011, 02:51 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

What chapter or page number is this referring to?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 22nd, 2011, 05:04 PM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Oops, I should have posted this in ASP.NET 3.5 Basics - sorry about that.

I can repost there if it is possible to delete this thread?
 
Old June 23rd, 2011, 05:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Not sure, but you could simply post it again....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 23rd, 2011, 10:25 AM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default moved...

I re-posted this to Basic ASP.NET:

How to set Default Formview data on a Master/Details page?

Feel free to delete this thread, and sorry about the mis-post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
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
Help With Master Details Code In PHP Book placebo Wrox Book Feedback 1 November 21st, 2003 04:17 AM





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