Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 rows from the same table - the grade 3 page displays only the grade 3-related table rows. If a user clicks a particular link in the GridView, the page posts back with the details for that record displayed in the FormView control.

My problem is when the page is first navigated to by a user, before the user has selected any records from the GridView: the FormView control defaults to displaying the first row in the source table when the page is first loaded, even if this is not from the group of rows associated with that page.

How can I force the FormView control to display a particular record upon Pageload, before the user has chosen any record from the gridview? Is this a simple PageLoad event in codebehind?

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).

Thanks very much for any advice!

Here is what the FormView's current datasource looks like:

XML
<asp:SqlDataSource ID="srcProductDetailsTeacher" runat="server"
    ConnectionString="<%$ ConnectionStrings:siteConnectionString %>"
    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>
Posted

1 solution

Ok, got it: I had set my "DefaultValue" to a row ID already without realising it.

As Emily Litella says, "Nevermind"...

<pre lang="xml"><SelectParameters>
    <asp:ControlParameter
        ControlID="grdStudentList"
        Name="ProductID"
        PropertyName="SelectedValue"
        Type="Int32"
        DefaultValue="8"/>
</SelectParameters>


 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900