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.