Displaying Gridview based upon row select

Discussion in 'ASP.NET / ASP.NET Core' started by collegefootballsim.com, Jan 27, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hey guys and gals,

    Basically, what I want to do is have my second gridview populate based upon the selected row in the first gridview. I am attaching the code below. I am getting the following error as is: Data keys must be specified on GridView 'GridView1' before the selected data keys can be retrieved. Use the DataKeyNames property to specify data keys.

    I thought this meant to specify that the "Workout Number" in Gridview1 needs to be declared as the datakeyname because it is the link between the two tables, however, it tells me I can't declare that as my datakeyname. So, now, I am officially stuck.

    Can anyone help me out?

    Code:
    <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" %>
    
    <script runat="server">
    
        Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    
        End Sub
    </script>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
        
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    
    
        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
            DataKeyNames="&quot;(Workout Number)&quot;">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="Workout Number" HeaderText="Workout Number" 
                    SortExpression="Workout Number" />
                <asp:BoundField DataField="Workout Name" HeaderText="Workout Name" 
                    SortExpression="Workout Name" />
                <asp:BoundField DataField="Level" HeaderText="Level" SortExpression="Level" />
                <asp:BoundField DataField="Days per Week" HeaderText="Days per Week" 
                    SortExpression="Days per Week" />
                <asp:BoundField DataField="Total Weeks" HeaderText="Total Weeks" 
                    SortExpression="Total Weeks" />
                <asp:BoundField DataField="Equipment" HeaderText="Equipment" 
                    SortExpression="Equipment" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>" 
            SelectCommand="SELECT * FROM [Workout List]"></asp:SqlDataSource>
        <br />
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource2">
            <Columns>
                <asp:BoundField DataField="Workout Number" HeaderText="Workout Number" 
                    SortExpression="Workout Number" />
                <asp:BoundField DataField="Workout Name" HeaderText="Workout Name" 
                    SortExpression="Workout Name" />
                <asp:BoundField DataField="Exercise Number" HeaderText="Exercise Number" 
                    SortExpression="Exercise Number" />
                <asp:BoundField DataField="Exercise Name" HeaderText="Exercise Name" 
                    SortExpression="Exercise Name" />
                <asp:BoundField DataField="Set One" HeaderText="Set One" 
                    SortExpression="Set One" />
                <asp:BoundField DataField="Set Two" HeaderText="Set Two" 
                    SortExpression="Set Two" />
                <asp:BoundField DataField="Set Three" HeaderText="Set Three" 
                    SortExpression="Set Three" />
                <asp:BoundField DataField="Set Four" HeaderText="Set Four" 
                    SortExpression="Set Four" />
                <asp:BoundField DataField="Week Number" HeaderText="Week Number" 
                    SortExpression="Week Number" />
                <asp:BoundField DataField="Exercise_Name" HeaderText="Exercise_Name" 
                    SortExpression="Exercise_Name" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>" 
            SelectCommand="SELECT * FROM [Workouts] WHERE ([Workout Number] = @Workout_Number) ORDER BY [Exercise Number] DESC">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="Workout_Number" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <br />
    
    
        </asp:Content>
    
    
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page