Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 23rd, 2011, 10:23 AM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
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.
  #2 (permalink)  
Old June 24th, 2011, 05:20 PM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
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!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.